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.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int H = Integer.valueOf(s.next());
		int W = Integer.valueOf(s.next());
		int[] start = new int[4]; //y, x, 歩数, ワープ
		int[] goal = new int[2];
		start[0] = Integer.valueOf(s.next()) - 1;
		start[1] = Integer.valueOf(s.next()) - 1;
		goal[0] = Integer.valueOf(s.next()) - 1;
		goal[1] = Integer.valueOf(s.next()) - 1;

		int[][] maze = new int[H][W];
		char[] cur;
		for(int i = 0; i < H; i++) {
			cur = s.next().toCharArray();
			for(int j = 0; j < W; j++) {
				maze[i][j] = cur[j] == '.' ? -1 : -2;
			}
		}

		int[] vx = {1, 0, -1, 0};
		int[] vy = {0, -1, 0, 1};
		int[][] vxw = new int[4][5];
		int[][] vyw = new int[4][5];

		vxw[0] = new int[]{2, 2, 2, 2, 2}; //20個
		vyw[0] = new int[]{2, 1, 0, -1, -2}; //20個
		vxw[1] = new int[]{1, 1, 0, -1, -1}; //20個
		vyw[1] = new int[]{-1, -2, -2, -2, -1}; //20個
		vxw[2] = new int[]{-2, -2, -2, -2, -2}; //20個
		vyw[2] = new int[]{-2, -1, 0, 1, 2}; //20個
		vxw[3] = new int[]{-1, -1, 0, 1, 1}; //20個
		vyw[3] = new int[]{1, 2, 2, 2, 1}; //20個

		PriorityQueue<int[]> Q = new PriorityQueue<>((a, b) -> Integer.compare(a[3], b[3]));
		Q.add(start);

		int[] now;
		int[] tmp = new int[4];
		int ret = -1;
		while(!Q.isEmpty()) {
			now = Q.poll();

			for(int i = 0; i < 4; i++) {
				tmp[0] = now[0] + vy[i];
				tmp[1] = now[1] + vx[i];

				// 範囲内チェック
				if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

					// 一回も行ってない
					if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {

						// 迷路が壁以外
						if(maze[tmp[0]][tmp[1]] != -2) {

							// ゴール
							if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
								System.out.println(now[3]);
								return;
							}

							maze[tmp[0]][tmp[1]] = now[3]; // 迷路の値を更新
							Q.add(new int[] {tmp[0], tmp[1], 0, now[3]});

						// 迷路が壁
						}else {

							for(int j = 0; j < 5; j++) {
								tmp[0] = now[0] + vyw[i][j];
								tmp[1] = now[1] + vxw[i][j];

								// 範囲内チェック
								if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

									// 一回も行ってない
									if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {
										// 迷路が壁以外
										if(maze[tmp[0]][tmp[1]] != -2) {

											// ゴール
											if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
												System.out.println(now[3] + 1);
												return;
											}
											maze[tmp[0]][tmp[1]] = now[3] + 1; // 迷路の値を更新
											Q.add(new int[] {tmp[0], tmp[1], 0, now[3] + 1});
											j++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(ret);
	}
}