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

public class Main {
    static int h, w;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        h = sc.nextInt(); w = sc.nextInt();
        int rs = sc.nextInt() - 1; int cs = sc.nextInt() - 1;
        int re = sc.nextInt() - 1; int ce = sc.nextInt() - 1;
        int [][] grid = new int[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            for (int j = 0; j < w; j++) if (s.charAt(j) == '#') grid[i][j] = 1;
        }
        int [][] dp = new int[h][w];
        int [] dx = new int[]{0, 1, -1, 2, -2};
        int [] dy = new int[]{0, 1, -1, 2, -2};
        PriorityQueue<State> q = new PriorityQueue<>(Comparator.comparingInt(x -> x.t));
        q.add(new State(rs, cs, 0));
        for (int [] arr: dp) Arrays.fill(arr, Integer.MAX_VALUE);
        while (!q.isEmpty()) {
            State next = q.poll();
            int r = next.r; int c = next.c; int t = next.t;
            dp[r][c] = Math.min(dp[r][c], t);
            for (Integer mx: dx) {
                for (Integer my: dy) {
                    if (mx == 0 && my == 0) continue;
                    int nr = r + mx; int nc = c + my;
                    if (!inBounds(nr, nc)) continue;
                    if (grid[nr][nc] == 1) continue;
                    if ((mx == 0 && my == 1) || (mx == 1 && my == 0) || (mx == -1 && my == 0) || (mx == 0 && my == -1)) {
                        if (t < dp[nr][nc]) {
                            dp[nr][nc] = t;
                            if (nr == re && nc == ce) continue;
                            q.add(new State(nr, nc, t));
                        }
                    } else {
                        if (t + 1 < dp[nr][nc]) {
                            dp[nr][nc] = t + 1;
                            if (nr == re && nc == ce) continue;
                            q.add(new State(nr, nc, t + 1));
                        }
                    }
                }
            }
        }
        out.println(dp[re][ce] == Integer.MAX_VALUE ? -1 : dp[re][ce]);
        out.close();
    }

    static boolean inBounds(int r, int c) {
        return (r >= 0 && r < h)  && (c >= 0 && c < w);
    }

    static class State {
        int r; int c; int t;
        State (int r, int c, int t) {
            this.r = r; this.t = t; this.c = c;
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}