#include using namespace std; #define rep(i,n) for(long long i = 0; i < (long long)(n); i++) using ll = long long; using vll = vector; using vvll = vector; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } // x, yをマージ bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } // x, yが同じ集合なら1 bool find(int x, int y) { return root(x) == root(y); } // xの根を探す。同じ集合なら同じ根が帰る int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } }; #define get(i, j) (b[i+buff/2][j+buff/2]) #define encode(i, j) (i*w+j) int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll h, w; cin >> h >> w; ll sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; const int buff = 10; vvll b(h+buff, vll(w+buff, -5)); rep(i, h) { string s; cin >> s; rep(j, s.length()) { get(i, j) = s[j] - '0'; } } vll di = {1, -1, 0, 0}; vll dj = {0, 0, 1, -1}; UnionFind uf(h*w); rep(i, h) { rep(j, w) { rep(d, 4) { ll nexti = i + di[d]; ll nextj = j + dj[d]; if (abs(get(i, j) - get(nexti, nextj)) <= 1) uf.unite(encode(i, j), encode(nexti, nextj)); } rep(d, 4) { ll nexti = i + di[d] * 2; ll nextj = j + dj[d] * 2; if (get(i, j) == get(nexti, nextj) && get(i, j) > get(i + di[d], j + dj[d])) uf.unite(encode(i, j), encode(nexti, nextj)); } } } if (uf.find(encode(sx, sy), encode(gx, gy))) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }