#include <bits/stdc++.h>
using namespace std;
int n,m,sx,sy,ex,ey,ans=0,tmp;
bool vis[20][20];
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
string str;
void dfs(int x,int y){
if(x==ex&&y==ey){
ans++;
return;
}
for(int i=0;i<4;i++){
int px=x+dx[i],py=y+dy[i];
if(vis[px][py]||px<1|px>n||py<1||py>m)continue;
vis[px][py]=1;
int len=str.length();
str='('+to_string(px)+' '+to_string(py)+')';
dfs(px,py);
vis[px][py]=0;
str=str.substr(0,len);
}
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>tmp;
vis[i][j]=!tmp;
}
cin>>sx>>sy>>ex>>ey;
if(vis[sx][sy]==1||vis[ex][ey]==1){
str='('+to_string(sx)+' '+to_string(sy)+')';
cout<<-1;
return 0;
}
vis[sx][sy]=1;
dfs(sx,sy);
if(ans==0)cout<<-1;
return 0;
}