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.util.*;
public class Main {
	static char[][] arr;
	static int n,m;
	static int dn,dm,cn,cm;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=1;//sc.nextInt();
		while(t-->0) {
			n=sc.nextInt();m=sc.nextInt();
			cn=sc.nextInt();cm=sc.nextInt();
			dn=sc.nextInt();dm=sc.nextInt();
			dn--;cn--;dm--;cm--;
			arr=new char[n][m];
			for(int i=0;i<n;i++) {
				arr[i]=sc.next().toCharArray();
			}
			LinkedList<Integer> xqu=new LinkedList<>();
			LinkedList<Integer> yqu=new LinkedList<>();
			xqu.add(cn);yqu.add(cm);
			int[][] dist=new int[n][m];
			//System.out.println(dist.length);
			for(int i=0;i<n;i++) {
				Arrays.fill(dist[i], Integer.MAX_VALUE);
			}
			dist[cn][cm]=0;
			while(xqu.size()>0) {
				int x=xqu.pollFirst();
				int y=yqu.pollFirst();
				int[][] dr= {{0,1},{0,-1},{1,0},{-1,0}};
				for(int[] d:dr) {
					int nx=x+d[0];int ny=y+d[1];
					if(!islegal(nx,ny)) continue;
					if(dist[nx][ny]>dist[x][y]) {
						dist[nx][ny]=dist[x][y];
						xqu.addFirst(nx);
						yqu.addFirst(ny);
					}
				}
				for(int i=x-2;i<=x+2;i++) {
					for(int j=y-2;j<=y+2;j++) {
						int nx=i;int ny=j;
						if(!islegal(nx,ny)) continue;
						
						if(dist[nx][ny]>dist[x][y]+1) {
							dist[nx][ny]=dist[x][y]+1;
							xqu.addLast(nx);
							yqu.addLast(ny);
						}
					}
				}
			}
			System.out.println(dist[dn][dm]==Integer.MAX_VALUE? -1:dist[dn][dm]);
		}

	}
	static boolean islegal(int x,int y) {
		if(x<0 || y<0 ||x>=n || y>=m) return false;
		if(arr[x][y]=='#') return false;
		return true;
	}
	static class node{
		int x,y,k;
		node(int x,int y){
			this.x=x;this.y=y;
			this.k=0;
		}
	}

}
/*class Reader{
	BufferedReader reader;
	Reader(){
		reader=new BufferedReader(new InputStreamReader(System.in));
	}
	int nextInt() throws IOException{
		String in=reader.readLine().trim();
		return Integer.parseInt(in);
	}
	long nextLong() throws IOException{
		String in=reader.readLine().trim();
		return Long.parseLong(in);
	}
	String next() throws IOException{
		return reader.readLine().trim();
	}
	String[] stringArray() throws IOException{
		return reader.readLine().trim().split("\\s+");
	}
	int[] intArray() throws IOException{
		String[] inp=this.stringArray();
		int[] arr=new int[inp.length];
		int i=0;
		for(String s:inp) {
			arr[i++]=Integer.parseInt(s);
		}
		return arr;
	}
}*/