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 in = new FastReader();

	public static void main(String[] args) {
		solve();
	}	

	static int[] di = {0, 0, 1, -1};
    static int[] dj = {1, -1, 0, 0};
    static int INF = 100000000;
    static int h, w;
	
	static void solve() {
		h = in.nextInt();
		w = in.nextInt();
		int ch = in.nextInt() - 1;
		int cw = in.nextInt() - 1;
		int dh = in.nextInt() - 1;
		int dw = in.nextInt() - 1;
		
		String[][] arr = new String[h][w];
		for(int i = 0; i < h; i++)
		{
			arr[i] = in.nextLine().split("");
		}
		
		ArrayDeque<int[]> q = new ArrayDeque();
		int[][] dist = new int[h][w];
		for(int i = 0; i < h; i++) Arrays.fill(dist[i], INF);
		q.add(new int[] {ch, cw});
		dist[ch][cw]= 0;
		while(!q.isEmpty()) {
			int[] tmp = q.pollFirst();
			int i = tmp[0];
			int j = tmp[1];
			int curDist = dist[i][j];
			for(int k = 0; k < 4; k++)
			{
				int ni = i + di[k];
				int nj = j + dj[k];
				if(in(ni, nj) && arr[ni][nj].equals(".") && dist[ni][nj] > curDist)
				{
					dist[ni][nj] = curDist;
					q.addFirst(new int[] {ni, nj});
				}
			}
			
			for(int a = -2; a <= 2; a++)
			{
				for(int b = -2; b <= 2; b++)
				{
					int ni = i + a;
					int nj = j + b;
					if(in(ni, nj) && arr[ni][nj].equals(".") && dist[ni][nj] > curDist + 1)
					{
						dist[ni][nj] = curDist + 1;
						q.addLast(new int[] {ni, nj});
					}
				}
			}
			
			
		}
		int ret = dist[dh][dw];
		if(ret >= INF) ret = -1;
		System.out.println(ret);
		
	}
	static boolean in(int a, int b)
	{
		return 0 <= a && a < h && 0 <= b && b < w;
	}
		
	
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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

		int[] readarr(int abc) {
			int[] a = new int[abc];
			for (int i = 0; i < abc; i++)
				a[i] = nextInt();
			return a;
		}
	}
	
}

class Pair
{
	
}