import java.util.LinkedList;
import java.util.Scanner;
public class Grasshop {
static private final int [][] offsety = new int[][] {
{1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}
};
static private LinkedList<int[]> zoznam;
public static void main
(String[] args
) { Scanner scanner
= new Scanner
(System.
in);
while(scanner.hasNextInt()) {
int width = scanner.nextInt();
int height = scanner.nextInt();
int posX = scanner.nextInt()-1;
int posY = scanner.nextInt()-1;
int goalX = scanner.nextInt()-1;
int goalY = scanner.nextInt()-1;
if(posX == goalX && posY == goalY) {
} else {
int [] [] pole = new int[width][height];
zoznam = new LinkedList<int[]>();
zoznam.add(new int [] {0, posX, posY});
while(!zoznam.isEmpty()) {
int[] prvok = zoznam.getFirst();
zoznam.removeFirst();
for(int[] offset : offsety) {
int newPosX = prvok[1] + offset[0];
int newPosY = prvok[2] + offset[1];
if(newPosX < 0 || newPosX >= pole.length || newPosY < 0 || newPosY >= pole[0].length) {
continue;
}
if(pole[newPosX][newPosY] == 0)
zoznam.addLast(new int[] {prvok[0]+1, newPosX, newPosY});
pole[newPosX][newPosY] = prvok[0]+1;
if(newPosX == goalX && newPosY == goalY) {
zoznam.clear();
break;
}
}
}
int hodnota = pole[goalX][goalY];
if(hodnota == 0) {
System.
out.
println("impossible"); } else {
}
}
}
}
}