Problem: A maze is composed of a grid of H \times W squares - H vertical, W horizontal.

The square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is `#` and a road if S_{ij} is `.`.

There is a magician in (C_h,C_w). He can do the following two kinds of moves:

* Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.
* Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in.



In either case, he cannot go out of the maze.

At least how many times does he need to use the magic to reach (D_h, D_w)?

Constraints

* 1 \leq H,W \leq 10^3
* 1 \leq C_h,D_h \leq H
* 1 \leq C_w,D_w \leq W
* S_{ij} is `#` or `.`.
* S_{C_h C_w} and S_{D_h D_w} are `.`.
* (C_h,C_w) \neq (D_h,D_w)

Input

Input is given from Standard Input in the following format:


H W
C_h C_w
D_h D_w
S_{11}\ldots S_{1W}
\vdots
S_{H1}\ldots S_{HW}


Output

Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead.

Examples

Input

4 4
1 1
4 4
..#.
..#.
.#..
.#..


Output

1


Input

4 4
1 4
4 1
.##.


.##.


Output

-1


Input

4 4
2 2
3 3
....
....
....
....


Output

0


Input

4 5
1 2
2 5
.###
.
..##
..##


Output

2

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    static int H;
    static int W;
    static int Ch;
    static int Cw;
    static int Dh;
    static int Dw;
    static char[][] maze;
    static boolean[][] find;
    static int[] X = new int[] { 0, 1, 0, -1 };
    static int[] Y = new int[] { 1, 0, -1, 0 };
    static int ans = Integer.MAX_VALUE;
    static boolean findAns = false;

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        H = sc.nextInt();
        W = sc.nextInt();
        Ch = sc.nextInt() - 1;
        Cw = sc.nextInt() - 1;
        Dh = sc.nextInt() - 1;
        Dw = sc.nextInt() - 1;
        maze = new char[H][W];
        find = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            maze[i] = s.toCharArray();
        }
        LinkedList<int[]> queue = new LinkedList<>();
        dfs(Ch, Cw, queue, 0);
        int count = 1;
        while (!queue.isEmpty() && ans == Integer.MAX_VALUE) {
            int size = queue.size();
            for (int a = 0; a < size; a++) {
                int[] pop = queue.pollFirst();
                if (inMaze(pop[0], pop[1])) {
                    int newX = pop[0] - 2;
                    int newY = pop[1] - 2;
                    for (int i = newX; i < newX + 5; i++) {
                        for (int j = newY; j < newY + 5; j++) {
                            if (inMaze(i, j)) {
                                if (!find[i][j] && maze[i][j] != '#') {
                                    dfs(i, j, queue, count);
                                }
                            }
                        }
                    }
                }
            }
            count++;
        }
        System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
    }

    public static void dfs(int height, int width, LinkedList<int[]> queue, int count) {
        if (!inMaze(height, width)) {
            return;
        }
        if (find[height][width] || maze[height][width] == '#')
            return;
        find[height][width] = true;
        if (height == Dh && width == Dw) {
            ans = Math.min(count, ans);
            findAns = true;
        }
        queue.addLast(new int[] {height, width});
        for (int i = 0; i < 4; i++) {
            int newX = height + X[i];
            int newY = width + Y[i];
            dfs(newX, newY, queue, count);
        }
    }

    public static boolean inMaze(int x, int y) {
        return x >= 0 && x < maze.length && y >= 0 && y < maze[0].length;
    }

    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}