from collections import deque H,W=map(int,input().split()) A=[list(map(int,input().split())) for _ in range(H)] G=[[] for _ in range(H*W)] into_num=[0]*(H*W) def xy_to_x_y(xy): return xy//W,xy%W def x_y_to_xy(x,y): return x*W+y dx=[0,1,0,-1] dy=[1,0,-1,0] for i in range(H): for j in range(W): for k in range(4): new_x=i+dx[k] new_y=j+dy[k] if(0<=new_x