# 接收数据区域
n,m = list(map(int,input().split()))
list1 = []
for i in range(n):
list1.append(list(input()))
def bfs(list1,i,j):
queue = [] # 定义一个队列
forward = [(0,-1),(0,1),(-1,0),(1,0)] # 可以移动的四个方向
queue.insert(0,(i,j)) # 将首个点添加到队列
while len(queue) > 0: # 出循环的条件是队列为空
temp = queue.pop() # 获取队首出队的值
i = temp[0]
j = temp[1]
for _ in forward: # 对某点可移动方向遍历
x = _[0]
y = _[1]
if 0 <= i+x and i+x < row and 0 <= j+y and j+y < col\
and ord(list1[i+x][j+y]) > 48: # 并且该点的值不为0 以字符串读入,所以要转为数字
queue.insert(0,(i+x,j+y)) # 将该点的坐标加入队尾
list1[i+x][j+y] = '0' # 将该点标记为0
return
# 获取行列
row = len(list1)
col = len(list1[0])
con = 0
# 循环遍历每一个点
for i in range(row):
for j in range(col):
if ord(list1[i][j]) > 48:
bfs(list1,i,j)
con += 1
print(con)
con = 0
for i in range(row):
for j in range(col):
if ord(list1[i][j]) > 48:
bfs(list1,i,j)
con += 1
print(con)