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.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

    static String flag = "1";

    static int[] dx = { 1, -1, 0, 0 };
    static int[] dy = { 0, 0, 1, -1 };

    static int[] warpx = { -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
    static int[] warpy = { -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2 };

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int w = Integer.parseInt(scan.next());
        int ch = Integer.parseInt(scan.next());
        int cw = Integer.parseInt(scan.next());
        int dh = Integer.parseInt(scan.next());
        int dw = Integer.parseInt(scan.next());
        ch--;
        cw--;
        dh--;
        dw--;
        String[][] s = new String[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = scan.next().split("");
        }
        scan.close();

        long ans = 0;

        Deque<Pair> stack = new ArrayDeque<Pair>();
        s[ch][cw] = flag;
        stack.push(new Pair(ch, cw));

        while (true) {
            List<Pair> warpList = new ArrayList<Pair>();
            while (!stack.isEmpty()) {
                Pair p = stack.poll();

                for (int i = 0; i < dx.length; i++) {
                    int x = p.h + dx[i];
                    int y = p.w + dy[i];

                    if (x == dh && y == dw) {
                        System.out.println(ans);
                        return;
                    }

                    if (0 <= x && x < h && 0 <= y && y < w) {
                        if (s[x][y].equals(".")) {
                            s[x][y] = flag;
                            stack.push(new Pair(x, y));
                        }
                    }
                }

                warpList.add(p);
            }

            ans++;
            for (Pair p : warpList) {
                for (int i = 0; i < warpx.length; i++) {
                    int x = p.h + warpx[i];
                    int y = p.w + warpy[i];
                    if (0 <= x && x < h && 0 <= y && y < w) {
                        if (x == dh && y == dw) {
                            System.out.println(ans);
                            return;
                        }

                        if (s[x][y].equals(".")) {
                            s[x][y] = flag;
                            stack.push(new Pair(x, y));
                        }
                    }
                }
            }

            if (stack.isEmpty()) {
                break;
            }
        }
        System.out.println(-1);
    }

    static class Pair {
        int h;
        int w;

        public Pair(int h, int w) {
            this.h = h;
            this.w = w;
        }
    }
}