import sys input = sys.stdin.readline from collections import deque N,V,x,y,zz,ww=map(int,input().split()) MAP=[list(map(int,input().split())) for i in range(N)] x,y=y,x zz,ww=ww,zz V=min(V,1800) x-=1 y-=1 zz-=1 ww-=1 DP=[1<<30]*(N*N*(V+1)) DP[V*(N*N)+x*N+y]=0 Q=deque() Q.append((0,V,x*N+y)) while Q: now,power,xy=Q.popleft() if xy==zz*N+ww: print(now) break x=xy//N y=xy%N for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z0 and DP[(power-dec)*N*N+nec]>now+1: DP[(power-dec)*N*N+nec]=now+1 Q.append((now+1,power-dec,nec)) else: print(-1)