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.*;
public class Main {
	public static void main(String[] args){
        Main main = new Main();
        main.input();
        main.solve();
        main.output();
    }

    int H;
    int W;
    Point start;
    int goalH;
    int goalW;
    boolean[][] maze;
    boolean[][] visited;
    Queue<Point> queue;
    Queue<Point> frontArea;
    int warp;
    int result;

    private void input() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        start = new Point(sc.nextInt(), sc.nextInt());
        queue = new ArrayDeque<>();
        queue.add(start);
        frontArea = new ArrayDeque<>();
        goalH = sc.nextInt();
        goalW = sc.nextInt();        
        maze = new boolean[W][H];
        visited = new boolean[W][H];
        for (int i=0; i<H; i++) {
            char[] line = sc.next().toCharArray();
            for (int j=0; j<W; j++) {
                maze[j][i] = ('.' == line[j]);
            }
        }
        visited[start.x-1][start.y-1] = true;
        warp = 0;
        result = -1;
    }

    private void solve() {
        if (start.x == goalW && start.y == goalH) { result = warp; return; }
        for (; ; ) {
            if (result > -1) { return; }
            if (queue.size() < 1) {
                warp();
                if (visited[goalW-1][goalH-1]) {
                    return;
                }
                if (queue.size() > 0) {
                    continue;
                } else {
                    return;
                }
            }
            Point point = queue.poll();
            frontArea.add(point);
            // System.out.println("poll:" + point.x + "," + point.y);
            // System.out.println("queue.size()=" + queue.size());
            // up
            if (point.y - 1 > 0) { visit(point.x, point.y - 1); }
            // down
            if (point.y + 1 < H+1) { visit(point.x, point.y + 1); }
            // left
            if (point.x - 1 > 0) { visit(point.x - 1, point.y); }
            // right
            if (point.x + 1 < W+1) { visit(point.x + 1, point.y); }
        }
    }

    private void warp() { 
        warp++;
        while (frontArea.size() > 0){
            if (result > -1) { return; }
            Point point = frontArea.poll();
            int x = point.x;
            int y = point.y;
            if (maze[x-1][y-1]) {
                if (y - 2 > 0) {
                    if (x - 2 > 0) { visit(x - 2, y - 2); }
                    if (x - 1 > 0) { visit(x - 1, y - 2); }
                    { visit(x, y - 2); }
                    if (x + 1 < W+1) { visit(x + 1, y - 2); }
                    if (x + 2 < W+1) { visit(x + 2, y - 2); }
                }
                if (y - 1 > 0) {
                    if (x - 2 > 0) { visit(x - 2, y - 1); }
                    if (x - 1 > 0) { visit(x - 1, y - 1); }
                    if (x + 1 < W+1) { visit(x + 1, y - 1); }
                    if (x + 2 < W+1) { visit(x + 2, y - 1); }
                }
                {
                    if (x - 2 > 0) { visit(x - 2, y); }
                    if (x + 2 < W+1) { visit(x + 2, y); }
                }
                if (y + 1 < H+1) {
                    if (x - 2 > 0) { visit(x - 2, y + 1); }
                    if (x - 1 > 0) { visit(x - 1, y + 1); }
                    if (x + 1 < W+1) { visit(x + 1, y + 1); }
                    if (x + 2 < W+1) { visit(x + 2, y + 1); }
                }
                if (y + 2 < H+1) {
                    if (x - 2 > 0) { visit(x - 2, y + 2); }
                    if (x - 1 > 0) { visit(x - 1, y + 2); }
                    { visit(x, y + 2); }
                    if (x + 1 < W+1) { visit(x + 1, y + 2); }
                    if (x + 2 < W+1) { visit(x + 2, y + 2); }
                }
            }
        }
    }

    private void visit(int x, int y) {
        if (!visited[x-1][y-1]) {
            visited[x-1][y-1] = true;
            if (maze[x-1][y-1]) {
                if (goalH == y && goalW == x) {
                    result = warp;
                    return;
                }
                queue.add(new Point(y, x));
                // System.out.println("add:" + x + "," + y);
                // System.out.println("queue.size()=" + queue.size());
            }
        }
    }

    private void output() {
        System.out.println(result);
    }
}

class Point {
    public int y;
    public int x;

    public Point(int y, int x) {
        this.y = y;
        this.x = x;
    }
}