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.*;
class Pair implements Comparable<Pair>
{
    int r;
    int c;
    int dist;
    public Pair(int r,int c,int d)
    {
        this.r=r;
        this.c=c;
        this.dist=d;
    }
    public int compareTo(Pair p)
    {
        if(this.dist>p.dist)
        return 1;
        else if(this.dist<p.dist)
        return -1;
        return 0;
    }
}
public class Main {
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int h;
	static int w;
	static boolean possible(int r,int c)
	{
		if(r>=0 && r<h && c>=0 && c<w)
			return true;
		return false;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int[]ar=split();
		h=ar[0];
	    w=ar[1];
		ar=split();
		int sr=ar[0]-1;
		int sc=ar[1]-1;
		ar=split();
		int er=ar[0]-1;
		int ec=ar[1]-1;
		char[][] mat=new char[h][w];
		for(int i=0;i<h;i++)
		{
			String s=br.readLine();
			for(int j=0;j<w;j++)
			{
				mat[i][j]=s.charAt(j);
			}
		}
		PriorityQueue<Pair>pq=new PriorityQueue<>();
		pq.add(new Pair(sr,sc,0));
		int[][] dis=new int[h][w];
		for(int i=0;i<h;i++)
		{
			Arrays.fill(dis[i],1000000000);
		}
		dis[sr][sc]=0;
		while(!pq.isEmpty())
		{
			Pair p=pq.poll();
			int d=p.dist;
			int r=p.r;
			int c=p.c;
			if(d>dis[r][c])
				continue;
			for(int i=r-2;i<=r+2;i++)
			{
				for(int j=c-2;j<=c+2;j++)
				{
					if(!possible(i,j) || ((i==r)&&(j==c)) || (mat[i][j]=='#'))
						continue;
					int d1=1;
					if((Math.abs(i-r)==1 && j==c) || (Math.abs(j-c)==1 && i==r))
						d1=0;
					if(dis[r][c]+d1<dis[i][j])
					{
						dis[i][j]=dis[r][c]+d1;
						pq.add(new Pair(i,j,dis[i][j]));
					}
				}
			}
		}
		if(dis[er][ec]!=1000000000)
		System.out.println(dis[er][ec]);
		else
			System.out.println(-1);
	}
}