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 {

    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    List<List<Pair>> lists = new ArrayList<>();
    int c1 = sc.nextInt() - 1;
    int c2 = sc.nextInt() - 1;
    int d1 = sc.nextInt() - 1;
    int d2 = sc.nextInt() - 1;
    char[][] arr = new char[h][w];
    int[] dy = {1, 0, -1, 0};
    int[] dx = {0, 1, 0, -1};
    int[][] warpCnt = new int[h][w];
    boolean[][] flag = new boolean[h][w];


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

    void run() {

        for (int i=0; i<h; i++) {
            arr[i] = sc.next().toCharArray();
        }

//        List<Pair> list = new ArrayList<>();
//        list.add(new Pair(c1, c2));
        bfs(new Pair(c1, c2));

//        for (int i=0; i<h; i++) {
//            for (int j=0; j<w-1; j++) {
//                System.out.print(warpCnt[i][j] + " ");
//            }
//            System.out.println(warpCnt[i][w-1]);
//        }

        if (!flag[d1][d2]) System.out.println(-1);
        else System.out.println(warpCnt[d1][d2]);

    }

    void bfs(Pair pair){
        Queue<Pair> queue = new ArrayDeque<>();
        queue.add(pair);
        List<Pair> list = new ArrayList<>();
        list.add(pair);
        while (!queue.isEmpty()){
            Pair p = queue.peek();
            int y = p.y;
            int x = p.x;
            flag[y][x] = true;
            for (int i=0; i<4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny<0 || h<=ny || nx<0 || w<=nx) continue;
                if (flag[ny][nx]) continue;
                if (arr[ny][nx] == '#') continue;
                flag[ny][nx] = true;
                list.add(new Pair(ny, nx));
                queue.add(new Pair(ny, nx));
                warpCnt[ny][nx] = warpCnt[y][x];
            }
            queue.poll();
            if (queue.isEmpty()) {
                if (list.size()==0) break;
                List<Pair> list1 = new ArrayList<>();
                for (Pair pair1: list) {
                    int y1 = pair1.y;
                    int x1 = pair1.x;
                    for (int yy=-2; yy<=2; yy++) {
                        for (int xx=-2; xx<=2; xx++) {
                            int nyy = y1 + yy;
                            int nxx = x1 + xx;
                            if (yy==0 && xx==0) continue;
                            if (nyy<0 || h<=nyy || nxx<0 || w<=nxx) continue;
                            if (arr[nyy][nxx] == '#') continue;
                            if (flag[nyy][nxx]) continue;
                            queue.add(new Pair(nyy, nxx));
                            list1.add(new Pair(nyy, nxx));
                            warpCnt[nyy][nxx] = warpCnt[y1][x1] + 1;
                        }
                    }
                }
                list.clear();
                list = list1;
            }
        }
    }



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



}