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.*;
import java.math.*;
 
public class Main
{
    static class Node{
        int r, c, dist;

        public Node(int r, int c, int dist){
            this.r = r;
            this.c = c;
            this.dist = dist;
        }
    }

    static boolean isValid(int x, int y, int n, int m){
        return !(x <= 0 || x > n || y <= 0 || y > m);
    }

    public static void process(int test_number)throws IOException
    {
        int h = ni(), w = ni(), c_h = ni(), c_w = ni(), d_h = ni(), d_w = ni(),
            nr = 0, nc = 0;

        char grid[][] = new char[h + 1][];
        for(int i = 1; i <= h; i++)
            grid[i] = (" "+nln()).toCharArray();

        Node arr[][] = new Node[h + 1][w + 1];
        for(int i = 1; i <= h; i++)
            for(int j = 1; j <= w; j++)
                arr[i][j] = new Node(i, j, oo); 

        arr[c_h][c_w].dist = 0;
        PriorityQueue<Node> q = new PriorityQueue<>((A, B) -> A.dist - B.dist);
        q.add(arr[c_h][c_w]);

        while(!q.isEmpty()){
            Node nn = q.poll();
            int r = nn.r, c = nn.c, dist = nn.dist;

            for(int i = 0; i < 4; i++){
                nr = r + x_coord[i];
                nc = c + y_coord[i]; 

                if(!isValid(nr, nc, h, w) || grid[nr][nc] == '#')
                    continue;

                if(dist < arr[nr][nc].dist){
                    arr[nr][nc].dist = dist;
                    if(q.contains(arr[nr][nc]))
                        q.remove(arr[nr][nc]);

                    q.add(arr[nr][nc]);  
                }
            }

            for(int i = -2; i <= 2; i++){
                for(int j = -2; j <= 2; j++){
                    if(Math.abs(i) + Math.abs(j) == 1)
                        continue;

                    nr = r + i;
                    nc = c + j;

                    //if(r == 2 && c == 2 && nr == 4 && nc == 4) trace(dist, arr[nr][nc].dist);
                    if(!isValid(nr, nc, h, w) || grid[nr][nc] == '#')
                        continue;

                    //if(r == 2 && c == 2 && nr == 4 && nc == 4) trace(dist, arr[nr][nc].dist);
                    if(dist + 1 < arr[nr][nc].dist){

                        arr[nr][nc].dist = dist + 1;
                        if(q.contains(arr[nr][nc]))
                            q.remove(arr[nr][nc]);

                        q.add(arr[nr][nc]);
                    }
                }
            }
        }

        int x = arr[d_h][d_w].dist;
        pn(x == oo ? -1 : x);
    }
     
    static int oo = 12345678, x_coord[] = {1, 0, -1, 0}, y_coord[] = {0, 1, 0, -1};
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
        //t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            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(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}