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.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int H = in.nextInt();
        int W = in.nextInt();
        int Ch = in.nextInt() - 1;
        int Cw = in.nextInt() - 1;
        int Dh = in.nextInt() - 1;
        int Dw = in.nextInt() - 1;
        int[][] grid = new int[H][W];
        for (int h = 0; h < H; h++) {
            String S = in.next();
            for (int w = 0; w < W; w++) {
                if (S.charAt(w) == '#')
                    grid[h][w] = -1;
                else
                    grid[h][w] = Integer.MAX_VALUE;
            }
        }
        Deque<Integer> Nh = new ArrayDeque<>();
        Deque<Integer> Nw = new ArrayDeque<>();
        Deque<Integer> Nd = new ArrayDeque<>();
        grid[Ch][Cw] = 0;
        Nh.addFirst(Ch);
        Nw.addFirst(Cw);
        Nd.addFirst(0);
        while (!Nh.isEmpty()) {
            int h = Nh.pollFirst();
            int w = Nw.pollFirst();
            int d = Nd.pollFirst();
            if (grid[h][w] != d)
                continue;
            if (h > 0 && grid[h - 1][w] > grid[h][w]) {
                grid[h - 1][w] = grid[h][w];
                Nh.addFirst(h - 1);
                Nw.addFirst(w);
                Nd.addFirst(grid[h][w]);
            }
            if (h < H - 1 && grid[h + 1][w] > grid[h][w]) {
                grid[h + 1][w] = grid[h][w];
                Nh.addFirst(h + 1);
                Nw.addFirst(w);
                Nd.addFirst(grid[h][w]);
            }
            if (w > 0 && grid[h][w - 1] > grid[h][w]) {
                grid[h][w - 1] = grid[h][w];
                Nh.addFirst(h);
                Nw.addFirst(w - 1);
                Nd.addFirst(grid[h][w]);
            }
            if (w < W - 1 && grid[h][w + 1] > grid[h][w]) {
                grid[h][w + 1] = grid[h][w];
                Nh.addFirst(h);
                Nw.addFirst(w + 1);
                Nd.addFirst(grid[h][w]);
            }
            for (int x = Math.max(0, h - 2); x <= h + 2 && x < H; x++)
                for (int y = Math.max(0, w - 2); y <= w + 2 && y < W; y++) {
                    if (grid[x][y] > grid[h][w] + 1) {
                        grid[x][y] = grid[h][w] + 1;
                        Nh.addLast(x);
                        Nw.addLast(y);
                        Nd.addLast(grid[h][w] + 1);
                    }
                }
        }
        if (grid[Dh][Dw] == Integer.MAX_VALUE)
            out.println(-1);
        else
            out.println(grid[Dh][Dw]);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}