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.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int H=nextInt();
		int W=nextInt();
		int ch=nextInt()-1;
		int cw=nextInt()-1;
		int dh=nextInt()-1;
		int dw=nextInt()-1;
		boolean S[][]=new boolean[H][W];
		boolean V[][]=new boolean[H][W];
		boolean wv[][]=new boolean[H][W];
		int min[][]=new int[H][W];
		Deque<Integer> X=new ArrayDeque<Integer>();
		Deque<Integer> Y=new ArrayDeque<Integer>();
		Deque<Integer> wx=new ArrayDeque<Integer>();
		Deque<Integer> wy=new ArrayDeque<Integer>();
		Deque<Integer> wc=new ArrayDeque<Integer>();
		for(int i=0;i<H;i++){
			String a=next();
			for(int j=0;j<W;j++){
				char b=a.charAt(j);
				if(b=='.')
					S[i][j]=true;
			}
		}
		X.add(cw);Y.add(ch);
		V[ch][cw]=true;
		while(X.size()>0){
			while(X.size()>0){
				int x=X.poll();
				int y=Y.poll();
				for(int i=y-2;i<y+3;i++){
					for(int j=x-2;j<x+3;j++){
						if((i!=y||j!=x)&&0<=i&&i<H&&0<=j&&j<W)
							if(((i==y&&j==x-1)||(i==y&&j==x+1)||(i==y-1&&j==x)||(i==y+1&&j==x))&&V[i][j]==false){
								if(S[i][j]){
									X.add(j);Y.add(i);
									min[i][j]=min[y][x];
									V[i][j]=true;
								}
							}
							else
								if(S[i][j]&&wv[i][j]==false){
									wx.add(j);wy.add(i);wc.add(min[y][x]+1);
									wv[i][j]=true;
								}
					}
				}
			}
			while(wx.size()>0){
				int x=wx.poll();
				int y=wy.poll();
				int cnt=wc.poll();
				if(V[y][x]==false){
					min[y][x]=cnt;
					X.add(x);Y.add(y);
					V[y][x]=true;
				}
			}
		}
		if(V[dh][dw]==false)
			System.out.println(-1);
		else
			System.out.println(min[dh][dw]);
	}
	public static long lmod(long i, long j) {
	     return (i%j)<0?(i%j)+0+(j<0?-j:j):(i%j+0);
	 }
	static boolean isOK(int index,int key,int[]a){
		if (a[index]>=key) return true;
	    else return false;
	}
	static int binary_search(int key,int[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}