w,h=map(int,input().split()) m=[list(map(int,input().split())) for i in range(h)] v=[[0]*w for i in range(h)] for i in range(h): for j in range(w): v=[[0]*w for x in range(h)] x,y=i,j v[x][y]=1 q=[(x,y,x,y)] for x,y,xxx,yyy in q: dx,dy=1,0 for _ in range(4): xx,yy=x+dx,y+dy if 0<=xx