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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll H,W,i,j,c=0;P S,G;cin>>H>>W>>S.F>>S.S>>G.F>>G.S;bool X[H][W];ll Y[H][W];deque<P>B,C;
  REP(i,H)REP(j,W){char s;cin>>s;X[i][j]=(s=='.');Y[i][j]=H*W;}S.F--;S.S--;G.F--;G.S--;
  B.push_back(S);Y[S.F][S.S]=0;vector<P>O(4);
  O.at(0)=P(-1,0);O.at(1)=P(0,-1);O.at(2)=P(1,0);O.at(3)=P(0,1);
  while(B.size()+C.size()&&c<7000000){
    P E;if(B.size()){E=B.front();B.pop_front();}else{E=C.front();C.pop_front();}
    REP(i,4){
      ll x=E.F+O.at(i).F,y=E.S+O.at(i).S;
      if(0<=x&&x<H&&0<=y&&y<W&&X[x][y]&&Y[x][y]>Y[E.F][E.S]){
        Y[x][y]=Y[E.F][E.S];B.push_back(P(x,y));
      }
    }
    FOR(i,-2,3)FOR(j,-2,3)if(abs(i)+abs(j)>1){
      ll x=E.F+i,y=E.S+j;
      if(0<=x&&x<H&&0<=y&&y<W&&X[x][y]&&Y[x][y]>Y[E.F][E.S]+1){
        Y[x][y]=Y[E.F][E.S]+1;C.push_back(P(x,y));
      }
    }
  }
  if(Y[G.F][G.S]==H*W)Y[G.F][G.S]=-1;
  cout<<Y[G.F][G.S]<<endl;
  return 0;
}