#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template constexpr T TEN(int n) {return (n==0)?1:10*TEN(n-1);} int bsr(int x) { return 31 - __builtin_clz(x); } const int MN = 52; int g[MN][MN]; bool ok[MN][MN]; const int d4[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, }; int main() { int h, w; cin >> h >> w; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; sy--; sx--; gy--; gx--; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { g[i][j] = s[j]-'0'; } } auto bc = [&](int x, int y) { return (0 <= x && x < w && 0 <= y && y < h); }; ok[sy][sx] = true; while (true) { bool update = false; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (!ok[i][j]) continue; for (int d = 0; d < 4; d++) { int ni = i+2*d4[d][0]; int nj = j+2*d4[d][1]; int mi = (ni+i)/2; int mj = (nj+j)/2; if (bc(nj, ni) && g[ni][nj] == g[i][j] && g[mi][mj] < g[i][j]) { if (!ok[ni][nj]) { update = true; ok[ni][nj] = true; } } } for (int d = 0; d < 4; d++) { int ni = i+d4[d][0]; int nj = j+d4[d][1]; if (bc(nj, ni) && abs(g[ni][nj] - g[i][j]) <= 1) { if (!ok[ni][nj]) { update = true; ok[ni][nj] = true; } } } } } if (!update) break; } if (ok[gy][gx]) { printf("YES\n"); } else { printf("NO\n"); } return 0; }