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.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.NoSuchElementException;

public class Main {

	static int H;
	static int W;
	static int Ch;
	static int Cw;
	static int Dh;
	static int Dw;
	static char[][] maze;
	static boolean[][] find;
	static int[] X = new int[] { 0, 1, 0, -1 };
	static int[] Y = new int[] { 1, 0, -1, 0 };
	static int ans = Integer.MAX_VALUE;
	static boolean findAns = false;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		H = sc.nextInt();
		W = sc.nextInt();
		Ch = sc.nextInt() - 1;
		Cw = sc.nextInt() - 1;
		Dh = sc.nextInt() - 1;
		Dw = sc.nextInt() - 1;
		maze = new char[H][W];
		find = new boolean[H][W];
		for (int i = 0; i < H; i++) {
			String s = sc.next();
			maze[i] = s.toCharArray();
		}
		LinkedList<int[]> queue = new LinkedList<>();
		dfs(Ch, Cw, queue, 0);
		int count = 1;
		while (!queue.isEmpty() && ans == Integer.MAX_VALUE) {
			int size = queue.size();
			for (int z = 0; z < size; z++) {
				int[] pop = queue.pollFirst();
				if (inMaze(pop[0], pop[1])) {
					int newX = pop[0] - 2;
					int newY = pop[1] - 2;
					for (int i = newX; i < newX + 5; i++) {
						for (int j = newY; j < newY + 5; j++) {
							if (inMaze(i, j)) {
								if (!find[i][j] && maze[i][j] != '#') {
									dfs(i, j, queue, count);
								}
							}
						}
					}
				}
			}
			count++;
		}
		System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
	}

	public static void dfs(int h, int w, LinkedList<int[]> queue, int count) {
		if (!inMaze(h, w)) {
			return;
		}
		if (find[h][w] || maze[h][w] == '#')
			return;
		find[h][w] = true;
		if (h == Dh && w == Dw) {
			ans = Math.min(count, ans);
			findAns = true;
		}
		queue.addLast(new int[] {h, w});
		for (int i = 0; i < 4; i++) {
			int newX = h + X[i];
			int newY = w + Y[i];
			dfs(newX, newY, queue, count);
		}
	}

	public static boolean inMaze(int x, int y) {
		return x >= 0 && x < maze.length && y >= 0 && y < maze[0].length;
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}