/*dfs*/
#include<bits/stdc++.h>
using namespace std;
int m,n,p,q,minn;
int a[60][60],book[60][60];
void dfs(int x,int y,int step);
int main(){
int i,j,startx,starty;
while(cin>>m>>n){
minn=9999999;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cin>>a[i][j];
}
}
cin>>startx>>starty>>p>>q;
startx--;
starty--;
p--;
q--;
book[startx][starty]=1;
dfs(startx,starty,0);
if(minn==9999999){
cout<<"No Way!"<<endl;
}
else
cout<<minn<<endl;
}
return 0;
}
void dfs(int x,int y,int step){
int next[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int tx,ty,k;
if(x==p and y==q){
if(step<minn)
minn=step;
return ;
}
for(k=0;k<4;k++){
tx=x+next[k][0];
ty=y+next[k][1];
if(tx<0 or tx>m-1 or ty<0 or ty>n-1)
continue;
if(a[tx][ty]==0 and book[tx][ty]==0){
book[tx][ty]=1;
dfs(tx,ty,step+1);
book[tx][ty]=0;
}
}
return ;
}
/*个人版dfs*/
#include<bits/stdc++.h>
using namespace std;
int m,n,q,p,minn;
int a[60][60],book[60][60];
void dfs(int x,int y,int step);
int main(){
while(cin>>m>>n){
minn=9999999;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int startx,starty;
cin>>startx>>starty>>p>>q;
startx--;
starty--;
p--;
q--;
dfs(startx,starty,0);
if(minn==9999999){
cout<<"No Way!"<<endl;
}
else{
cout<<minn<<endl;
}
}
return 0;
}
void dfs(int x,int y,int step){
int next[4][2]={{1,0},{0,1},{-1,0},{0,-1}};//逆时针
int tx,ty;
if(x==p and y==q){
if(step<minn)
minn=step;
return ;
}
for(int k=0;k<4;k++){
tx=x+next[k][0];
ty=y+next[k][1];
if(tx<0 or tx>m-1 or ty<0 or ty>n-1)
continue;
if(a[tx][ty]==0 and book[tx][ty]==0){
book[tx][ty]=1;
dfs(tx,ty,step+1);
book[tx][ty]=0;
}
}
return ;
}
/*bfs*/
#include<bits/stdc++.h>
using namespace std;
typedef struct note{
int x;
int y;
int step;
}notes;
int main(){
notes que[3000];
int a[60][60],book[60][60];
int next[4][2]={1,0,-1,0,0,1,0,-1};
int head,tail,i,j,k,m,n,p,q,startx,starty,tx,ty,flag;
while(cin>>m>>n){
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cin>>a[i][j];
}
}
cin>>startx>>starty>>p>>q;
startx--;
starty--;
p--;
q--;
head=0;
tail=0;
que[tail].x=startx;
que[tail].y=starty;
que[tail].step=0;
tail++;
book[startx][starty]=1;
flag=0;
while(head<tail){
for(k=0;k<4;k++){//该循环将宽度搜索的点塞入数组
tx=que[head].x+next[k][0];
ty=que[head].y+next[k][1];
if(tx<0 or tx>m-1 or ty<0 or ty>n-1)
continue;
if(a[tx][ty]==0 and book[tx][ty]==0){
book[tx][ty]=1;
que[tail].x=tx;
que[tail].y=ty;
que[tail].step=que[head].step+1;
tail++;
}
if(tx==p and ty==q){
flag=1;
break;
}
}
if(flag==1)
break;
head++;
}
cout<<que[tail-1].step<<endl;//只要第一个到达终点即最短
}
return 0;
}