import sys
from collections import deque
r,c = map(int,input().split())
data = []
for _ in range(r):
data.append(list(input()))
dirs = [(1,0), (-1,0), (0,1), (0,-1)]
q = deque()
s = 0
for i in range(r):
for j in range(c):
if data[i][j] == '0':
q = deque()
flag = 1
q.append((i,j))
data[i][j] = '*'
cnt = 0
while q:
x, y = q.popleft()
if x==0 or y==0 or x==r-1 or y == c-1:
flag = 0
cnt+=1
for dx,dy in dirs:
nx, ny = x+dx, y+dy
if 0<=nx<r and 0<=ny<c and data[nx][ny]=='0':
q.append((nx,ny))
data[nx][ny] = '*'
if flag:
s+=cnt
print(s)