import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Horse { private int[][] board; private int[] xer = { 2, 1, -1, -2, -2, -1, 1, 2 }; private int[] yer = { 1, 2, 2, 1, -1, -2, -2, -1 }; private final static int A_BIG_NUMBER = 10000; private final static int UPPER_BOUND = 64; public Horse(int n) { board = new int[n][n]; } private int solution(int x, int y, int destx, int desty, int move) { if(move == UPPER_BOUND) { /* lets put an upper bound to avoid stack overflow */ return A_BIG_NUMBER; } if(x == 6 && y ==5) { board[6][5] = 1; return 1; } int min = A_BIG_NUMBER; for (int i = 0 ; i < xer.length; i++) { if (isMoveGood(x + xer[i], y + yer[i])) { if(board[x + xer[i]][y + yer[i]] != 0) { min = Integer.min(min, 1 + board[x +xer[i]] [y +yer[i]]); } else { min = Integer.min(min, 1 + solution(x + xer[i], y + yer[i], destx, desty, move + 1)); } } } board[x][y] = min; return min; } private boolean isMoveGood(int x, int y) { if (x >= 0 && x < board.length && y >= 0 && y < board.length) return true; return false; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); final Horse h = new Horse(n); int solution = h.solution(i_start, j_start, i_end, j_end, 0); if(solution == 10000){ System.out.println("Impossible"); }else{ System.out.println(solution); } in.close(); } }