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

public class Main {
    char[][] map;
    int[][] roads;
    int h;
    int w;

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        h = Integer.parseInt(tokenizer.nextToken());
        w = Integer.parseInt(tokenizer.nextToken());
        tokenizer = new StringTokenizer(f.readLine());
        int x0 = Integer.parseInt(tokenizer.nextToken()) - 1;
        int y0 = Integer.parseInt(tokenizer.nextToken()) - 1;
        tokenizer = new StringTokenizer(f.readLine());
        int x1 = Integer.parseInt(tokenizer.nextToken()) - 1;
        int y1 = Integer.parseInt(tokenizer.nextToken()) - 1;
        map = new char[h][w];
        for (int i = 0; i <h; i++) map[i] = f.readLine().toCharArray();

        roads = new int[h][w];
        for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) roads[i][j] = -1;
        int currRoad = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (map[i][j] == '.' && roads[i][j] == -1) {
                    ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
                    roads[i][j] = currRoad;
                    int[] pos = {i, j};
                    queue.addLast(pos);
                    while (!queue.isEmpty()) {
                        pos = queue.removeFirst();

                        for (int x = -1; x <= 1; x += 2) {
                            if (goodAdjacent(pos[0] + x, pos[1])) {
                                roads[pos[0] + x][pos[1]] = currRoad;
                                int[] newPos = {pos[0] + x, pos[1]};
                                queue.addLast(newPos);
                            }
                        }

                        for (int y = -1;  y <= 1; y += 2) {
                            if (goodAdjacent(pos[0], pos[1] + y)) {
                                roads[pos[0]][pos[1] + y] = currRoad;
                                int[] newPos = {pos[0], pos[1] + y};
                                queue.addLast(newPos);
                            }
                        }
                    }
                    currRoad++;
                }
            }
        }

        HashSet<Integer>[] connectedTo = new HashSet[currRoad];
        for (int i = 0; i < currRoad; i++) connectedTo[i] = new HashSet<Integer>();

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int k = -2; k <= 2; k++) {
                    for (int l = -2; l <= 2; l++) {
                        if (map[i][j] == '#') continue;
                        if (goodMagic(roads[i][j], i + k, j + l)) {
                            connectedTo[roads[i][j]].add(roads[i + k][j + l]);
                        }
                    }
                }
            }
        }

        int[] startRoad = {roads[x0][y0], 0};
        int[] shortesPathToRoad = new int[currRoad];
        Arrays.fill(shortesPathToRoad, -1);
        boolean[] visited = new boolean[currRoad];
        ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
        visited[startRoad[0]] = true;
        queue.addLast(startRoad);
        while (!queue.isEmpty()) {
            int[] road = queue.removeFirst();
            //System.out.println(road[0] + " " + road[1]);
            shortesPathToRoad[road[0]] = road[1];
            for (int adjacent : connectedTo[road[0]]) {
                if (!visited[adjacent]) {
                    int[] newRoad = {adjacent, road[1] + 1};
                    visited[adjacent] = true;
                    queue.addLast(newRoad);
                }
            }
        }

        out.println(shortesPathToRoad[roads[x1][y1]]);

        out.close();
    }

    private boolean goodAdjacent(int i, int j) {
        return i >= 0 && i < h && j >= 0 && j < w  && map[i][j] == '.' && roads[i][j] == -1;
    }

    private boolean goodMagic(int road, int i, int j) {
        return i >= 0 && i < h && j >= 0 && j < w  && map[i][j] == '.' && roads[i][j] != road;
    }
}