from collections import deque N,V,Sy,Sx,Gy,Gx = map(int,raw_input().split()) L=[] for i in range(N): line = map(int,raw_input().split()) L.append(line) que=deque([(0,Sx-1,Sy-1,V)]) arrived=[[0 for i in range(N)]for j in range(N)] dxs=[1,0,-1,0] dys=[0,1,0,-1] while len(que)!=0: dist,x,y,v = que.popleft() if arrived[x][y]>v: continue arrived[x][y]=v #print dist,y,x,v if (x,y)==(Gx-1,Gy-1): print dist exit() for dx,dy in zip(dxs,dys): nx,ny=x+dx,y+dy if nx>=0 and ny >= 0 and nx