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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayDeque;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        static int h;
        static int w;
        static char[][] board;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            h = in.nextInt();
            w = in.nextInt();
            int sy = in.nextInt() - 1, sx = in.nextInt() - 1;
            int ey = in.nextInt() - 1, ex = in.nextInt() - 1;
            ArrayDeque<Integer> xs = new ArrayDeque<>(), ys = new ArrayDeque<>();
            board = new char[w][h];
            for (int y = 0; y < h; y++)
            {
                char[] line = in.next().toCharArray();
                for (int x = 0; x < w; x++)
                {
                    board[x][y] = line[x];
                }
            }
            xs.add(sx);
            ys.add(sy);
            int[][] dist = new int[w][h];
            for (int x = 0; x < w; x++) Arrays.fill(dist[x], 1_000_000_000);
            dist[sx][sy] = 0;
            int[] dx = {-1, 1, 0, 0};
            int[] dy = {0, 0, -1, 1};
            while (!xs.isEmpty())
            {
                int curX = xs.removeFirst(), curY = ys.removeFirst();
                for (int d = 0; d < 4; d++)
                {
                    int nx = curX + dx[d], ny = curY + dy[d];
                    if (!legal(nx, ny)) continue;
                    if (dist[nx][ny] > dist[curX][curY])
                    {
                        dist[nx][ny] = dist[curX][curY];
                        xs.addFirst(nx);
                        ys.addFirst(ny);
                    }
                }
                for (int x = curX - 2; x <= curX + 2; x++)
                {
                    for (int y = curY - 2; y <= curY + 2; y++)
                    {
                        if (!legal(x, y)) continue;
                        if (dist[x][y] > dist[curX][curY] + 1)
                        {
                            dist[x][y] = dist[curX][curY] + 1;
                            xs.addLast(x);
                            ys.addLast(y);
                        }
                    }
                }
            }
            out.println(dist[ex][ey] > 1e7 ? -1 : dist[ex][ey]);
        }

        static boolean legal(int x, int y)
        {
            if (x < 0 || y < 0 || x >= w || y >= h || board[x][y] == '#') return false;
            return true;
        }

    }
}