import sys input = sys.stdin.readline from heapq import heappop,heappush H,W=map(int,input().split()) A=[list(map(int,input().split())) for i in range(H-2)] DP=[[1<<63]*W for i in range(H-2)] Q=[] for i in range(H-2): if A[i][0]!=-1: DP[i][0]=A[i][0] Q.append((DP[i][0],i,0)) Q.sort() while Q: now,x,y=heappop(Q) if DP[x][y]!=now: continue for z in range(x-1,x+2): for w in range(y-1,y+2): if x==z and y==w: continue if 0<=z