#include using namespace std; #define MAX 52 int r[MAX][MAX]; int sx; int sy; int gx; int gy; int h; int w; int id[MAX][MAX]; bool use[MAX][MAX]; queue > q; int dx[] = { 0, 0, 1, -1 }; int dy[] = { 1, -1, 0, 0 }; bool ok(int a, int b){ return a >= 0 && b >= 0 && a < h&&b < w; } int main(){ cin >> h >> w; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; int cc = 0; for (int i = 0; i < h; i++){ for (int j = 0; j < w; j++){ id[i][j] = cc; } } for (int i = 0; i < h; i++){ string s; cin >> s; for (int j = 0; j < w; j++){ r[i][j] = s[j] - '0'; } } q.push(make_pair(sx, sy)); use[sx][sy] = true; while (!q.empty()){ int x = q.front().first; int y = q.front().second; q.pop(); for (int i = 0; i < 4; i++){ int xx = x + dx[i]; int yy = y + dy[i]; if (ok(xx, yy)){ if (abs(r[xx][yy] - r[x][y]) <= 1){ if (use[xx][yy] == false){ use[xx][yy] = true; q.push(make_pair(xx, yy)); } } if (r[x][y] > r[xx][yy]){ int xxx = xx + dx[i]; int yyy = yy + dy[i]; if (ok(xxx, yyy)){ if (r[x][y] = r[xxx][yyy]){ if (use[xxx][yyy] == false){ q.push(make_pair(xxx, yyy)); use[xxx][yyy] = true; } } } } } } } if (use[gx][gy]){ puts("YES"); } else{ puts("NO"); } return 0; }