import java.util.Scanner;
public class Grasshop {
static int x;
static int y;
static int gx;
static int gy;
static int lx;
static int ly;
Scanner sc
= new Scanner
(System.
in); while (sc.hasNextInt()) {
x = sc.nextInt();
y = sc.nextInt();
gx = sc.nextInt() - 1;
gy = sc.nextInt() - 1;
lx = sc.nextInt() - 1;
ly = sc.nextInt() - 1;
int[][] map = new int[x][y];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
}
}
map[gx][gy] = 0;
boolean change = true;
while (change) {
change = false;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
change = jump(map, i, j) || change;
}
}
if (map
[lx
][ly
] < Integer.
MAX_VALUE) { change = false;
System.
out.
println(map
[lx
][ly
]);
}
/*
for (int j = 0; j < y; j++) {
for (int i = 0; i < x; i++) {
if (map[i][j] == Integer.MAX_VALUE) {
System.out.print(" - ");
} else {
System.out.print(map[i][j] + " ");
}
}
System.out.println();
}
System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
*/
}
if (map
[lx
][ly
] == Integer.
MAX_VALUE) { System.
out.
println("impossible"); }
}
}
public static boolean jump(int[][] map, int a, int b) {
int dx = 0;
int dy = 0;
boolean change = false;
//System.out.println("Solving..... " + a + ", " + b) ;
if (map
[a
][b
] == Integer.
MAX_VALUE) { return false;
}
for (int k=0; k < 8; k++) {
if (k == 0) {dx = -2; dy = -1;}
if (k == 1) {dx = -2; dy = 1;}
if (k == 2) {dx = -1; dy = -2;}
if (k == 3) {dx = -1; dy = 2;}
if (k == 4) {dx = 1; dy = -2;}
if (k == 5) {dx = 1; dy = 2;}
if (k == 6) {dx = 2; dy = -1;}
if (k == 7) {dx = 2; dy = 1;}
int newX = a + dx;
int newY = b + dy;
if (isValid(newX, newY)) {
if (map[a][b] + 1 < map[newX][newY]) {
map[newX][newY] = map[a][b] + 1;
//System.out.println(a + ", " + b + " changed ") ;
change = true;
}
}
}
return change;
}
public static boolean isValid(int a, int b) {
boolean valid = (a >= 0 && a < x && b >=0 && b < y);
//System.out.println(a + ", " + b + " : " + valid);
return valid;
}
}