import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main34 { public static void main(String[] args) { Main34 p = new Main34(); } public Main34(){ Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int v =sc.nextInt(); int sx =sc.nextInt()-1; int sy =sc.nextInt()-1; int gx =sc.nextInt()-1; int gy =sc.nextInt()-1; int[][] l = new int[n][n]; for(int i=0;i queue = new LinkedList<>(); queue.add(new Point(sx, sy, 0, 0)); while(!queue.isEmpty()){ Point p = queue.poll(); for(int i=0;i<4;i++){ int nx = dx[i] + p.x; int ny = dy[i] + p.y; if(nx<0 || l.length<=nx || ny <0 || l.length<=ny) continue; if(nx == gx && ny == gy && v>p.totall+l[ny][nx]) return p.dist+1; if(tl[ny][nx] > p.totall+l[ny][nx]){ tl[ny][nx] = p.totall+l[ny][nx]; queue.add(new Point(nx, ny, p.totall+l[ny][nx], p.dist+1)); } } } return -1; } private class Point{ int x; int y; int totall; int dist; public Point(int x, int y, int totall, int dist) { this.x = x; this.y = y; this.totall = totall; this.dist = dist; } } }