n,m=map(int,input().split())
list_c=[]
c=0
for i in range(n):
	list_t=(list(map(int,list(input()))))
	c+=list_t.count(0)
	list_c.append(list_t)
lake1,lake2=[],[]
for y in range(n):
	for x in range(m):
		bl=False
		if list_c[y][x]==0:
			if lake1==[]:
				lake1.append([x,y])
				bl=True
			elif y==0:
				if 0<x<m-1:
					if [x-1,y] in lake1 or [x+1,y] in lake1 :
						lake1.append([x,y])
						bl=True
				elif x==m-1:
					if [x-1,y] in lake1  :
						lake1.append([x,y])
						bl=True
			elif 0<y<m-1:
				if x==0:
					if [x+1,y] in lake1 or [x,y-1] in lake1 or [x,y+1] in lake1:
						lake1.append([x,y])
						bl=True
				elif 0<x<m-1:
					if [x-1,y] in lake1 or [x+1,y] in lake1 or [x,y-1] in lake1 or [x,y+1] in lake1:
						lake1.append([x,y])
						bl=True
				elif x==m-1:
					if [x-1,y] in lake1  or [x,y-1] in lake1  or [x,y+1]:
						lake1.append([x,y])
						bl=True
			elif y==m-1:
				if x==0:
					if [x+1,y] in lake1 or [x,y-1] in lake1:
						lake1.append([x,y])
						bl=True
				elif 0<x<m-1:
					if [x-1,y] in lake1 or [x+1,y] in lake1 or [x,y-1] in lake1:
						lake1.append([x,y])
						bl=True
				elif x==m-1:
					if [x-1,y] in lake1   or [x,y-1] in lake1:
						lake1.append([x,y])
						bl=True
			if not bl:
				lake2.append([x,y])
step=[]
for i in lake1:
	for j in lake2:
		step.append(abs(i[0]-j[0])+abs(i[1]-j[1])-1)
print(m*n-min(step)-c)