from collections import deque
import sys
n, m = map(int, sys.stdin.readline().split())
g = [list(sys.stdin.readline().strip()) for _ in range(n)]
d = [(-1,0),(1,0),(0,-1),(0,1)]
vis = [[0]*m for _ in range(n)]
col = 1
q = deque()

for i in range(n):
    for j in range(m):
        if g[i][j] == '0' and vis[i][j] == 0:
            q.append((i,j))
            vis[i][j] = col
            while q:
                x,y = q.popleft()
                for dx,dy in d:
                    nx = x+dx
                    ny = y+dy
                    if 0<=nx<n and 0<=ny<m and g[nx][ny]=='0' and vis[nx][ny]==0:
                        vis[nx][ny] = col
                        q.append((nx,ny))
            col += 1
dis = [[-1]*m for _ in range(n)]
q = deque()

for i in range(n):
    for j in range(m):
        if vis[i][j] != 0:
            dis[i][j] = 0
            q.append((i,j))

ans = 0
while q:
    x,y = q.popleft()
    for dx,dy in d:
        nx = x+dx
        ny = y+dy
        if 0<=nx<n and 0<=ny<m:
            if dis[nx][ny] == -1:
                dis[nx][ny] = dis[x][y]+1
                if vis[nx][ny] !=0 and vis[nx][ny]!=vis[x][y]:
                    print(n*m - dis[x][y])
                    exit()
                q.append((nx,ny))