#include using namespace std; #define INF 2000000000 #define MOD 1000000007 typedef long long ll; typedef pair P; int main() { int h, w; cin >> h >> w; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; string b[h+1]; for (int i = 1; i <= h; i++) { cin >> b[i]; } bool rec[h+1][w+1]; for (int i = 0; i <= h; i++) { for (int j = 0; j <= w; j++) { rec[i][j] = false; } } // start queue

q; q.push(P(sx,sy)); while (true) { if (q.empty()) { cout << "NO" << "\n"; return 0; } P tmp = q.front(); q.pop(); int x = tmp.first; int y = tmp.second; if (x==gx&&y==gy) { cout << "YES" << "\n"; return 0; } // cout << "debug " << x << " " << y << "\n"; if (rec[x][y]) { continue; } if (x-1>=1&&abs((b[x][y-1]-'0')-(b[x-1][y-1]-'0'))<=1) { q.push(P(x-1,y)); } if (y-1>=1&&abs((b[x][y-1]-'0')-(b[x][y-1-1]-'0'))<=1) { q.push(P(x,y-1)); } if (x+1<=h&&abs((b[x][y-1]-'0')-(b[x+1][y-1]-'0'))<=1) { q.push(P(x+1,y)); } if (y+1<=w&&abs((b[x][y-1]-'0')-(b[x][y+1-1]-'0'))<=1) { q.push(P(x,y+1)); } if (x-2>=1&&(b[x][y-1]==b[x-2][y-1])&&(b[x-1][y-1]-'0')<=(b[x-2][y-1]-'0')) { q.push(P(x-2,y)); } if (y-2>=1&&(b[x][y-1]==b[x][y-2-1])&&(b[x][y-1-1]-'0')<=(b[x][y-2-1]-'0')) { q.push(P(x,y-2)); } if (x+2<=h&&(b[x][y-1]==b[x+2][y-1])&&(b[x+1][y-1]-'0')<=(b[x][y-1]-'0')) { q.push(P(x+2,y)); } if (y+2<=w&&(b[x][y-1]==b[x][y+2-1])&&(b[x][y+1-1]-'0')<=(b[x][y+2-1]-'0')) { q.push(P(x,y+2)); } rec[x][y] = true; } }