def dfs(graph,v, visited):
dx = [0,0,1,-1]
dy = [1,-1,0,0]
if not visited[v[0]][v[1]]:
visited[v[0]][v[1]] = True
for i in range(4):
nx = v[0] + dx[i]
ny = v[1] + dy[i]
if 0<= nx< N and 0<= ny < M:
if not visited[nx][ny] and graph[nx][ny] == 0:
dfs(graph,(nx,ny),visited)
return True
return False
N,M = map(int, input().split())
graph = []
for i in range(N):
graph.append(list(map(int, input())))
visited = [[False for i in range(M)] for j in range(N)]
result = 0
for i in range(N):
for j in range(M):
if graph[i][j] == 0 and not visited[i][j]:
result += dfs(graph,(i,j), visited)
print(result)