#include using namespace std; int main() { int h , w; cin >> h >> w; int y1 , x1; cin >> y1 >> x1; y1--; x1--; int y2 , x2; cin >> y2 >> x2; y2--; x2--; vector s(h); for (int i = 0 ; i < h; i++) cin >> s[i]; queue qx; queue qy; qx.push(x1); qy.push(y1); s[y1][x1] = 'A'; vector> a(h , vector(w , 0)); while (!qx.empty()) { int x = qx.front(); int y = qy.front(); qx.pop(); qy.pop(); if (x == x2 && y == y2) { cout << a[x][y] << endl; break; } if (x + 1 < w && s[y][x + 1] == '.') { qx.push(x + 1); qy.push(y); s[y][x + 1] = 'A'; a[y][x + 1] = a[y][x] + 1; } if (x - 1 >= 0 && s[y][x - 1] == '.') { qx.push(x - 1); qy.push(y); s[y][x - 1] = 'A'; a[y][x - 1] = a[y][x] + 1; } if (y + 1 < h && s[y + 1][x] == '.') { qx.push(x); qy.push(y + 1); s[y + 1][x] = 'A'; a[y + 1][x] = a[y][x] + 1; } if (y - 1 >= 0 && s[y - 1][x] == '.') { qx.push(x); qy.push(y - 1); s[y - 1][x] = 'A'; a[y - 1][x] = a[y][x] + 1; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cout << a[i][j] << " "; } cout << endl; } return 0; }