rt
#include<bits/stdc++.h>
using namespace std;
deque<int>qx;
deque<int>qy;
deque<int>qstep;
char a[510][510];
bool book[510][510];
int posx[]={0,0,0,1,-1},posy[]={0,1,-1,0,0};
void clean(){
memset(book,0,sizeof(book));
while(!qx.empty()){
qx.pop_front();qy.pop_front();qstep.pop_front();
}
}
int main(){
int n,m,x1,y1,x2,y2,x,y,step;
cin>>n>>m;
while(!(m==0&&n==0)){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
cin>>x1>>y1>>x2>>y2;
qx.push_front(x1);qy.push_front(y1);qstep.push_front(0);
while(!qx.empty()){
x=qx.front(),y=qy.front(),step=qstep.front();
qx.pop_front();qy.pop_front();qstep.pop_front();
book[x][y]=1;
if(x==x2&&y==y2)break;
for(int i=1;i<=4;i++){
x+=posx[i];y+=posy[i];
if(x>=0&&x<n&&y>=0&&y<n&&book[x][y]==0){
if(a[x][y]==a[x-posx[i]][y-posy[i]])qx.push_front(x),qy.push_front(y),qstep.push_front(step);
else qx.push_back(x),qy.push_back(y),qstep.push_back(step+1);
}
x-=posx[i];y-=posy[i];
}
}
cout<<step<<endl;
cin>>n>>m;
clean();
}
return 0;
}