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.ArrayDeque;
import java.util.Deque;

public class Main {
	private static int h;
	private static int w;
	private static int ch;
	private static int cw;
	private static int dh;
	private static int dw;
	private static String[] s;
	private static Integer[][] res;

	private static class Point {
		final int h;
		final int w;

		Point(int inh, int inw) {
			h = inh;
			w = inw;
		}
	}
	private static Deque<Point> nxtLst = new ArrayDeque<Point>();

	private static Deque<Point> wpLst = new ArrayDeque<Point>();

	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		ch = sc.nextInt() - 1;
		cw = sc.nextInt() - 1;
		dh = sc.nextInt() - 1;
		dw = sc.nextInt() - 1;
		s = new String[h];
		res = new Integer[h][];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next();
		}
		for (int i = 0; i < h; i++) {
			res[i] = new Integer[w];
			for (int j = 0; j < w; j++) {
				if (s[i].charAt(j) == '#') {
					res[i][j] = -1;
				}
			}
		}

		nxtLst.add(new Point(ch, cw));
		for (int pt = 0;; pt++) {
			if (nxtLst.size() <= 0) {
				System.out.println(-1);
				return;
			}
			for (Point e : nxtLst) {
				find(e.h, e.w, pt);
				Integer rtn = res[dh][dw];
				if (rtn != null && rtn >= 0) {
					System.out.println(rtn);
					return;
				}
			}
			nxtLst.clear();
			for (Point e : wpLst) {
				for (int i = -2; i <= 2; i++) {
					for (int j = -2; j <= 2; j++) {
						if (i == 0 && j == 0) {
							continue;
						}
						int wpH = e.h + i;
						int wpW = e.w + j;
						if (wpH < 0 || wpH >= h || wpW < 0 || wpW >= w) {
							continue;
						}
						if (res[wpH][wpW] != null) {
							continue;
						}
						res[wpH][wpW] = -2;
						nxtLst.add(new Point(wpH, wpW));
					}
				}
			}
			wpLst.clear();
		}

	}

	public static Integer find(int targetH, int targetW, int pt) {
		if (targetH < 0 || targetH >= h || targetW < 0 || targetW >= w) {
			return -1;
		}
		if (res[targetH][targetW] != null) {
			if (res[targetH][targetW] == -1) {
				return -2;
			}
			if (res[targetH][targetW] >= 0) {
				return res[targetH][targetW];
			}
		}
		res[targetH][targetW] = pt;
		boolean wpflg = false;
		if (find(targetH + 1, targetW, pt) == -2) {
			wpflg = true;
		}
		if (find(targetH - 1, targetW, pt) == -2) {
			wpflg = true;
		}
		if (find(targetH, targetW + 1, pt) == -2) {
			wpflg = true;
		}
		if (find(targetH, targetW - 1, pt) == -2) {
			wpflg = true;
		}
		if (wpflg) {
			wpLst.push(new Point(targetH, targetW));
		}
		return 0;
	}

}