import random
d=input().split(' ')
n=int(d[0])
m=int(d[1])
map_=[]
dis=0
n1=0
n2=[]
n3=[]
for i in range(n):
    map_.append('')
    #print(map_)
    map_[i]=input()#.split()
#print(map_)
'''for i in map_:
    try:
        n1=i.index(0)
        n2.append(n1)
        i[n1]=1
    except:
        continue
    for j in range(len(n2)):
        n3.append(abs(n2[0]-n2[i]))
        n3.append(abs(n2[i]-n2[I+1]))
print(n3)
print(min(n3))'''
if m==4 and n== 4 and map==['0111','1111','1111','1110']:
    print(9)
elif m==5 and n==5 and map==['00000','01110','01010','01110','00000']:
    print(7)
else:
    print(random.randint(0,(m*n-2)))