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.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int sh = scan.nextInt()-1;
        int sw = scan.nextInt()-1;
        int gh = scan.nextInt()-1;
        int gw = scan.nextInt()-1;
        boolean[][] map = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            char[] d = scan.next().toCharArray();
            for (int j = 0; j < W; j++) {
                if (d[j] == '.') {
                    map[i][j] = true;
                } else {
                    map[i][j] = false;
                }
            }
        }
        long[][] ans = new long[H][W];
        for (int i = 0; i < H; i++) {
            Arrays.fill(ans[i], Long.MAX_VALUE);
        }
        PriorityQueue<Position> queue = new PriorityQueue<>(new PositionComparator());
        ans[sh][sw] = 0;
        queue.add(new Position(sw, sh, 0));
        int[][] move = new int[4][2];
        move[0][0] = -1;
        move[0][1] = 0;
        move[1][0] = 1;
        move[1][1] = 0;
        move[2][0] = 0;
        move[2][1] = -1;
        move[3][0] = 0;
        move[3][1] = 1;
        while(!queue.isEmpty()) {
            Position p = queue.poll();
            for (int i = 0; i < 4; i++) {
                if (p.x + move[i][0] < 0 || W <= p.x + move[i][0]) {
                    continue;
                }
                if (p.y + move[i][1] < 0 || H <= p.y + move[i][1]) {
                    continue;
                }
                if (!map[p.y + move[i][1]][p.x + move[i][0]]) {
                    continue;
                }
                if (ans[p.y][p.x] < ans[p.y + move[i][1]][p.x + move[i][0]]) {
                    ans[p.y + move[i][1]][p.x + move[i][0]] = ans[p.y][p.x];
                    queue.add(new Position(p.x + move[i][0], p.y + move[i][1], ans[p.y][p.x]));
                }
            }
            for (int i = -2; i <= 2; i++) {
                for (int j = -2; j <= 2; j++) {
                    if (i == 0 && j == 0) {
                        continue;
                    }
                    if (p.x + i < 0 || W <= p.x + i) {
                        continue;
                    }
                    if (p.y + j < 0 || H <= p.y + j) {
                        continue;
                    }
                    if (!map[p.y + j][p.x + i]) {
                        continue;
                    }
                    if (ans[p.y][p.x] == Long.MAX_VALUE) {
                        continue;
                    }
                    if (ans[p.y][p.x] + 1 < ans[p.y + j][p.x + i]) {
                        ans[p.y + j][p.x + i] = ans[p.y][p.x] + 1;
                        queue.add(new Position(p.x + i, p.y + j, ans[p.y][p.x] + 1));
                    }
                }
            }
        }
        if (ans[gh][gw] == Long.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans[gh][gw]);
        }
    }
    class Position {
        int x;
        int y;
        long distance;
        Position(int x, int y, long distance) {
            this.x = x;
            this.y = y;
            this.distance = distance;
        }
    }
    class PositionComparator implements Comparator<Position> {
        @Override
        public int compare(Position o1, Position o2) {
            if (o1.distance != o2.distance) {
                return Long.compare(o1.distance, o2.distance);
            }
            if (o1.x != o2.x) {
                return Long.compare(o1.x, o2.x);
            }
            return Long.compare(o1.y, o2.y);
        }
    }
}