#include using namespace std; const std::vector dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1}; template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H, W; cin >> H >> W; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; sy--, sx--, gy--, gx--; vector> G(H, vector(W)); for (int i = 0; i < H; i++) { string s; cin >> s; for (int j = 0; j < W; j++) { G[i][j] = s[j] - '0'; } } vector> used(H, vector(W, false)); used[sy][sx] = true; queue> que; que.push(make_pair(sy, sx)); while (!que.empty()) { auto [y, x] = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int ny = y + dy[i], nx = x + dx[i]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (abs(G[y][x] - G[ny][nx]) <= 1 && !used[ny][nx]) { used[ny][nx] = true; que.push(make_pair(ny, nx)); } int nny = ny + dy[i], nnx = nx + dx[i]; if (nny < 0 || nny >= H || nnx < 0 || nnx >= W) continue; if (G[nny][nnx] == G[y][x] && G[y][x] > G[ny][nx] && !used[nny][nnx]) { used[nny][nnx] = true; que.push(make_pair(nny, nnx)); } } } if (used[gy][gx]) { cout << "YES" << '\n'; } else { cout << "NO" << '\n'; } return 0; }