#include using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N,K; cin>>N>>K; ll SY,SX,GY,GX; cin>>SY>>SX>>GY>>GX; SY--;SX--;GY--;GX--; bool ys=0,xs=0; if(SY>GY){ SY=N-SY-1; GY=N-GY-1; ys=1; } if(SX>GX){ SX=N-SX-1; GX=N-GX-1; xs=1; } ll d=(GX-SX)+(GY-SY); if(K2*K){ cout<<-1<<"\n"; } ll e=K-d; vector S(N,string(N,'.')); for(int i=0;i> D(N,vector(N,1e9)); D[SY][SX]=0; priority_queue,vector>,greater>> Q; Q.push({0,SY,SX}); vector u={0,1,0,-1,0}; while(!Q.empty()){ auto [c,y,x]=Q.top(); Q.pop(); if(D[y][x]!=c)continue; for(int dd=0;dd<4;dd++){ int ny=y+u[dd]; int nx=x+u[dd+1]; if(ny<0||nx<0||ny>=N||nx>=N)continue; ll nc=c+1+(S[ny][nx]!=S[y][x]); if(D[ny][nx]<=nc)continue; D[ny][nx]=nc; Q.push({nc,ny,nx}); } } assert(D[GY][GX]==K); if(ys)reverse(S.begin(),S.end()); if(xs){ for(int i=0;i