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.*;
class Main
{
    public static void main(String args[])throws IOException
    {
        //Reader in = new Reader();
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s1[] = in.readLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int m = Integer.parseInt(s1[1]);
        char[][] A = new char[n][m];
        s1 = in.readLine().split(" ");
        int cr = Integer.parseInt(s1[0]) - 1;
        int cc = Integer.parseInt(s1[1]) - 1;
        s1 = in.readLine().split(" ");
        int dr = Integer.parseInt(s1[0]) - 1;
        int dc = Integer.parseInt(s1[1]) - 1;
        for (int i=0;i<n;i++)
        {
            A[i] = in.readLine().toCharArray();
        }
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        ArrayDeque<Integer> X = new ArrayDeque<>();
        ArrayDeque<Integer> Y = new ArrayDeque<>();
        int[][] min = new int[n][m];
        for (int i=0;i<n;i++)
            Arrays.fill(min[i], Integer.MAX_VALUE);
        min[cr][cc] = 0;
        boolean[][] visited = new boolean[n][m];
        X.add(cr);
        Y.add(cc);
        while (X.size() > 0)
        {
            int xx = X.pollFirst();
            int yy = Y.pollFirst();
            if (visited[xx][yy])
                continue;
            visited[xx][yy] = true;
            if (A[xx][yy] == '#')
                continue;
            for (int i=0;i<4;i++)
            {
                int xxx = xx + dx[i];
                int yyy = yy + dy[i];
                if (xxx >= 0 && xxx < n && yyy >= 0 && yyy < m)
                {
                    X.addFirst(xxx);
                    Y.addFirst(yyy);
                    min[xxx][yyy] = Math.min(min[xxx][yyy], min[xx][yy]);
                }
            }
            for (int i=xx - 2;i<xx + 3;i++)
            {
                for (int j=yy - 2;j<yy + 3;j++)
                {
                    if (i >= 0 && i < n && j >= 0 && j < m)
                    {
                        X.addLast(i);
                        Y.addLast(j);
                        min[i][j] = Math.min(min[i][j], min[xx][yy] + 1);
                    }
                }
            }
        }
        if (min[dr][dc] == Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(min[dr][dc]);

    }

}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}