# Given N x M graph, find how many connected 0s are there in the graph.
#ex) 4 5
#    00110
#    00011
#    11111
#    00000
#    =>3


#code
N,M = map(int, input().split())
L = []
for i in range(N):
  L.append(list(map(int, input())))

def DFS(x,y):
  if x<=-1 or x>=N or y <=-1 or y>=M:
    return False

  if L[x][y] == 0:
    L[x][y] = 1
    DFS(x-1,y)
    DFS(x+1,y)
    DFS(x,y-1)
    DFS(x,y+1)
    return True
  return False

count = 0  
for i in range(len(L)):
  for j in range(M):
    if DFS(i,j) == True:
      count+=1
print(count)
