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.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
//		solveA(args);
//		solveB(args);
//		solveC(args);
		solveD(args);
//		solveE(args);
//		solveF(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solveA(String[] args) throws Exception{
		int N= nextInt();
		int X= nextInt();
		int T= nextInt();
		pw.println(((N+X-1)/X)*T);
	}
	public static void solveB(String[] args) throws Exception{
		String N = nextString();
		int sum =0;
		for(int i=0;i<N.length();i++) {
			sum+=N.charAt(i)-'0';
		}
		if(sum%9==00) {
			pw.println("Yes");
		}else {
			pw.println("No");
		}
	}
	public static void solveC(String[] args) throws Exception{
		int N = nextInt();
		long[] A = nextLongs();

		long ans = 0;
		for(int i=1;i<N;i++) {
			if(A[i-1]>A[i]) {
				ans+=A[i-1]-A[i];
				A[i]=A[i-1];
			}
		}

		pw.println(ans);
	}

	public static void solveD(String[] args) throws Exception{
		int H = nextInt();
		int W = nextInt();
		int Ch = nextInt()+1;
		int Cw = nextInt()+1;
		int Dh = nextInt()+1;
		int Dw = nextInt()+1;
		char[][] m = new char[H+4][W+4];
		Arrays.fill(m[0],'#');
		Arrays.fill(m[1],'#');
		Arrays.fill(m[m.length-2],'#');
		Arrays.fill(m[m.length-1],'#');
		for(int i=0;i<H;i++) {
			m[i+2]=("##"+nextString()+"##").toCharArray();
		}
		int[][] cost = new int[H+4][W+4];
		for(int i=0;i<cost.length;i++) {
			Arrays.fill(cost[i],-1);
		}

		ArrayDeque<int[]> queOver = new ArrayDeque<>();
		queOver.add(new int[] {Ch,Cw});

		cost[Ch][Cw]=0;
		//4方向の場合はx[i+around[n]][k+around[n+1]]n<4,8方向はn<8でループ
		int[] around = { -1, 0, 1, 0, -1, 1, 1, -1, -1 };

		while(!queOver.isEmpty()) {
			ArrayDeque<int[]> que = new ArrayDeque<>();
			que.add(queOver.poll());
			while(!que.isEmpty()) {
				int[] now = que.poll();
//				pw.println(now[0]+":"+now[1]);
				for(int i=0;i<4;i++) {
					int y = now[0]+around[i];
					int x = now[1]+around[i+1];
					if(m[y][x]=='.'&&(cost[y][x]==-1||cost[y][x] >cost[now[0]][now[1]])) {
						cost[y][x]=cost[now[0]][now[1]];
						que.offer(new int[] {y,x});
					}
				}
				for(int k=-2;k<3;k++) {
					for(int i=-2;i<3;i++) {
						int y = now[0]+k;
						int x = now[1]+i;
						if(m[y][x]=='.'&&(cost[y][x]==-1 || cost[y][x] > cost[now[0]][now[1]]+1)) {
							cost[y][x]=cost[now[0]][now[1]]+1;
							queOver.offer(new int[] {y,x});
						}
					}
				}
			}
		}
		pw.println(cost[Dh][Dw]);

	}


	public static void solveE(String[] args) throws Exception{

	}

	public static void solveF(String[] args) throws Exception{

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}