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.io.*;

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	static int[][] DIR = {{1,0},{0,1},{-1,0},{0,-1}};
	static int h, w;
	public static void main(String[] args) {
		h = f.nextInt();
		w = f.nextInt();
		
		int startI = f.nextInt() - 1, startJ = f.nextInt() - 1;
		int endI = f.nextInt() - 1, endJ = f.nextInt() - 1; 
		char[][] arr = new char[h][w];
		for(int i=0;i<h;i++) {
			arr[i] = f.next().toCharArray();
		}

		int[][] seg = new int[h][w];
		int lastSeg = 0;
		for(int i=0;i<h;i++) {
			for(int j=0;j<w;j++) {
				if(seg[i][j] == 0 && arr[i][j] != '#') {
					Queue<int[]> que = new ArrayDeque<>();
					que.add(new int[] {i,j});
					++lastSeg;
					seg[i][j] = lastSeg;
					
					while(!que.isEmpty()) {
						int[] now = que.poll();

						for(int[] d : DIR) {
							int nowI = now[0] + d[0];
							int nowJ = now[1] + d[1];

							if(good(nowI, nowJ) && arr[nowI][nowJ] == '.' && seg[nowI][nowJ] == 0) {
								seg[nowI][nowJ] = lastSeg;
								que.add(new int[]{nowI, nowJ});
							}
						}
					}
				}
			}
		}

		Node[] nodes = new Node[lastSeg+1];
		for(int i=0;i<=lastSeg;i++) {
			nodes[i] = new Node();
		}
		for(int i=0;i<h;i++) {
			for(int j=0;j<w;j++) {
				if(seg[i][j] == 0) {
					continue;
				}
				for(int k1=-2;k1<=2;k1++) {
					for(int k2=-2;k2<=2;k2++) {
						int nowI = i+k1, nowJ = j+k2;
						if(!good(nowI,nowJ)) {
							continue;
						}
						if(seg[nowI][nowJ] != 0 && seg[nowI][nowJ] != seg[i][j] && !nodes[seg[i][j]].set.contains(seg[nowI][nowJ])) {
							nodes[seg[i][j]].set.add(seg[nowI][nowJ]);
							nodes[seg[nowI][nowJ]].set.add(seg[i][j]);
						}
					}
				}
			}
		}

		int startNode = seg[startI][startJ];
		boolean[] vis = new boolean[lastSeg+1];
		Queue<Integer> que = new ArrayDeque<>();
		vis[startNode] = true;
		nodes[startNode].dist = 0;
		int dist = 0;
		que.add(startNode);

		while(!que.isEmpty()) {
			Queue<Integer> next = new ArrayDeque<>();
			dist++;

			while(!que.isEmpty()) {
				int now = que.poll();
				for(int i : nodes[now].set) {
					if(!vis[i]) {
						vis[i] = true;
						nodes[i].dist = dist;
						next.add(i);
					}
				}
			}

			que = next;
		}

		out.println(nodes[seg[endI][endJ]].dist == Integer.MAX_VALUE ? -1 : nodes[seg[endI][endJ]].dist);
		out.close();
	}
	
	static class Node {
		int dist = Integer.MAX_VALUE;
		TreeSet<Integer> set = new TreeSet<>();
	}

	static boolean good(int i, int j) {
		return 0 <= i && i < h && 0 <= j && j < w;
	}
	static class FastReader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String str = "";

			try {
				str = br.readLine();
			} catch(IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}
	}
}