#include using namespace std; int main() { vector mx={0,1,0,-1};vector my={1,0,-1,0}; int R,C,sy,sx,gy,gx,y,x,Y,X;scanf("%d %d %d %d %d %d",&R,&C,&sy,&sx,&gy,&gx); vector> c(R,vector(C));vector> dist(R,vector(C,-1)); for(int i=0;i>c[i][j]; queue que;que.push(sy-1);que.push(sx-1);dist[sy-1][sx-1]=0; while(!que.empty()) { y=que.front();que.pop();x=que.front();que.pop(); for(int i=0;i<4;i++) { Y=y+my[i];X=x+mx[i]; if(c[Y][X]!='.'||dist[Y][X]!=-1)continue; dist[Y][X]=dist[y][x]+1; que.push(Y);que.push(X); if(Y==gy-1&&X==gx-1){printf("%d\n",dist[gy-1][gx-1]);return 0;} } } }