H,W=map(int,input().split()) H-=2 A=[list(map(int,input().split())) for i in range(H)] INF=10**10 for i in range(H): for j in range(W): if A[i][j]==-1: A[i][j]=INF from heapq import * D=[[INF]*W for i in range(H)] Q=[] heapify(Q) for i in range(H): heappush(Q,(A[i][0],i,0)) D[i][0]=A[i][0] while len(Q): v=heappop(Q) x,y=v[1],v[2] if v[0]>D[x][y]: continue for i in range(-1,2): for j in range(-1,2): p,q=x+i,y+j if 0<=p and 0<=q and p