#include using namespace std; int main(){ int H, W; cin >> H >> W; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; vector S(H+2, string(W+2, '.')); for(int i=1; i<=H; i++){ string s; cin >> s; for(int j=0; j=0 && i=0 && j> que; que.emplace(sx, sy); vector> dist(H, vector(W, 1e9)); dist[sx][sy] = 0; while(que.size()){ auto p = que.front(); que.pop(); int i = p.first, j = p.second; for(int k=0; k<4; k++){ int x = i+dx[k], y = j+dy[k]; if(inside(x, y) && dist[x][y] == 1e9){ dist[x][y] = dist[i][j] + 1; que.emplace(x, y); } } } cout << dist[gx][gy] << endl; return 0; }