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.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	/** 道を表す文字 */
	private static final char ROAD = '.';

	/** 移動のX座標差分配列 */
	private static final int[] MOVE_XS = new int[] { 1, -1, 0, 0 };
	/** 移動のY座標差分配列 */
	private static final int[] MOVE_YS = new int[] { 0, 0, 1, -1 };
	/** ワープのX座標差分配列 */
	private static final int[] WARP_XS = new int[] { 1, 1, 1, 1, -1, -1, -1, -1, 2, 2, 2, 2, 2, -2, -2, -2, -2, -2, 0,
			0 };
	/** ワープのY座標差分配列 */
	private static final int[] WARP_YS = new int[] { 1, -1, 2, -2, 1, -1, 2, -2, 0, 1, -1, 2, -2, 0, 1, -1, 2, -2, 2,
			-2 };

	private static final int INF = Integer.MAX_VALUE >> 1;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int ch = scanner.nextInt() - 1, cw = scanner.nextInt() - 1;
			int dh = scanner.nextInt() - 1, dw = scanner.nextInt() - 1;
			boolean[][] road = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> {
				char[] s = scanner.next().toCharArray();
				IntStream.range(0, w).forEach(j -> road[i][j] = (ROAD == s[j]));
			});
			int[][] dp = new int[h][w];
			IntStream.range(0, h).forEach(i -> Arrays.fill(dp[i], INF));
			setDp(dp, h, w, ch, cw, road);
			System.out.println((INF == dp[dh][dw]) ? -1 : dp[dh][dw]);
		}
	}

	/**
	 * 個々のマスに移動するための最小コストの配列の値をセットする
	 * 
	 * @param dp   個々のマスに移動するための最小コストの配列
	 * @param h    縦幅
	 * @param w    横幅
	 * @param ch   開始時点
	 * @param cw   開始時点
	 * @param road 道路を表す配列
	 */
	private static void setDp(int[][] dp, int h, int w, int ch, int cw, boolean[][] road) {

		dp[ch][cw] = 0;
		Queue<Masu> queue = new PriorityQueue<>();
		queue.add(new Masu(ch, cw, 0));
		while (!queue.isEmpty()) {
			Masu masu = queue.poll();
			int nx = masu.x, ny = masu.y;
			if (masu.cost == dp[nx][ny]) {
				// 移動
				for (int i = 0; i < MOVE_XS.length; i++) {
					int newX = nx + MOVE_XS[i], newY = ny + MOVE_YS[i];
					if ((newX >= 0) && (newX < h) && (newY >= 0) && (newY < w) && road[newX][newY]) {
						if (dp[newX][newY] > dp[nx][ny]) {
							dp[newX][newY] = dp[nx][ny];
							queue.add(new Masu(newX, newY, dp[newX][newY]));
						}
					}
				}
				// ワープ
				for (int i = 0; i < WARP_XS.length; i++) {
					int newX = nx + WARP_XS[i], newY = ny + WARP_YS[i];
					if ((newX >= 0) && (newX < h) && (newY >= 0) && (newY < w) && road[newX][newY]) {
						if (dp[newX][newY] > dp[nx][ny] + 1) {
							dp[newX][newY] = dp[nx][ny] + 1;
							queue.add(new Masu(newX, newY, dp[newX][newY]));
						}
					}
				}
			}
		}
	}

	/**
	 * マスを表すクラス
	 */
	private static class Masu implements Comparable<Masu> {
		/** X座標 */
		int x;
		/** Y座標 */
		int y;
		/** ワープ数 */
		int cost;

		/**
		 * コンストラクタ
		 * 
		 * @param x
		 * @param y
		 * @param cost
		 */
		Masu(int x, int y, int cost) {
			super();
			this.x = x;
			this.y = y;
			this.cost = cost;
		}

		@Override
		public int compareTo(Masu masu) {
			return Integer.compare(cost, masu.cost);
		}
	}
}