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:
//package atcoder.beginnner_176;

import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

    static Stack<Integer> Ih = new Stack<>();
    static Stack<Integer> Iw = new Stack<>();

    public static void main (String[] args) throws Exception {

        String s = "4 4\n" +
                "1 1\n" +
                "4 4\n" +
                "..#.\n" +
                "..#.\n" +
                ".#..\n" +
                ".#..";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int H = nin(), W=nin();
        rl(); int ch = nin()-1, cw=nin()-1;
        rl(); int dh = nin()-1, dw=nin()-1;

        char S[][] = new char[H][]; int G[][] = new int[H][];
        for (int h=0; h<H; ++h) {
            rl();S[h]=nca(); G[h]=new int[W];
        }


        if (ch==dh && cw==dw) {
            bw.write(0 + "\n");
        } else if (S[dh][dw]=='#') {
            bw.write(-1 + "\n");
        } else {
            int c=1;
            Ih.push(ch); Iw.push(cw);
            while (G[dh][dw]==0 && !Ih.isEmpty()) {
                fill(S,G,H,W,c);
                ++c;
            }
            bw.write((G[dh][dw]==0?-1:(G[dh][dw]-1))+"\n");
        }

        bw.flush();
    }

    static int m[][] = new int[][]{new int[]{1,0}, new int[]{-1,0}, new int[]{0,1}, new int[]{0,-1}};

    static void fill(char S[][], int G[][], int H, int W, int c) {
        Set<Integer> B = new HashSet<>();
        while (!Ih.isEmpty()) {
            int _h = Ih.pop(); int _w=Iw.pop();
            if (G[_h][_w]!=0 || S[_h][_w]=='#') continue;
            G[_h][_w]=c;
            for (int[] _m:m) {
                int h2=_h+_m[0]; int w2=_w+_m[1];
                if (h2>H-1 || h2<0 || w2>W-1 || w2<0) continue;
                Ih.push(h2); Iw.push(w2);
            }
            for (int h3=_h-2; h3<=_h+2; ++h3) {
                for (int w3=_w-2; w3<=_w+2; ++w3) {
                    if (h3<0 || h3>H-1 || w3<0 || w3>W-1 || S[h3][w3]=='#' || G[h3][w3]!=0) continue;
                    B.add(h3*10_000+w3);
                }
            }
        }

        for (int b:B) {
            int _h=b/10_000, _w=b%10_000;
            Ih.push(_h); Iw.push(_w);
        }
    }

    static BufferedReader br; static BufferedWriter bw; static StringTokenizer st;
    static void rl() throws Exception{ st = new StringTokenizer(br.readLine()); }
    static long nlo(){ return Long.parseLong(st.nextToken()); }
    static int nin(){ return Integer.parseInt(st.nextToken()); }
    /*private static void te(){}*/
    static double ndo(){ return Double.parseDouble(st.nextToken()); }
    static char[] nca(){ return st.nextToken().toCharArray(); }
}