#pragma GCC optimize ("O3") #pragma GCC target ("avx") #pragma GCC optimize ("Ofast") #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) inline int gc()noexcept { return getchar_unlocked(); } inline int in()noexcept { int v = 0; char c = gc(); for (; isdigit(c); c = gc()) { v *= 10; v += c - '0'; } return v; } int par[2509]; inline int root(int x)noexcept { if (par[x] == x)return x; else return par[x] = root(par[x]); } inline void unite(int x, int y)noexcept { x = root(x); y = root(y); if (x == y)return; par[y] = x; } int s[51][51]; inline bool check(int x, int y)noexcept { return x >= y ? x <= y + 1 : y == x + 1; } int main() { int h = in(), w = in(); int sx = in() - 1, sy = in() - 1; int gx = in() - 1, gy = in() - 1; rep(i, h) { rep(j, w)s[i][j] = gc() - '0'; gc(); } int n = h * w; rep(i, n)par[i] = i; int ind = 0; rep(i, h) { rep(j, w - 1) { if (check(s[i][j], s[i][j + 1])) { unite(ind, ind + 1); } ++ind; } ++ind; } ind = 0; rep(i, h - 1) { rep(j, w) { if (check(s[i][j], s[i + 1][j])) { unite(ind, ind + w); } ++ind; } } ind = 0; rep(i, h) { rep(j, w - 2) { if (s[i][j] == s[i][j + 2] && s[i][j] > s[i][j + 1]) { unite(ind, ind + 2); } ++ind; } ind += 2; } ind = 0; rep(i, h - 2) { rep(j, w) { if (s[i][j] == s[i + 2][j] && s[i][j] > s[i + 1][j]) { unite(ind, ind + w + w); } ++ind; } } if (root(sx * w + sy) == root(gx * w + gy)) { puts("YES"); } else { puts("NO"); } }