#include using namespace std; int main(){ int H, W; cin >> H >> W; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; string S[1000]; for(int i=0; i> S[i]; auto inside = [&](int i, int j){ return i>=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; }