#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; class union_find { public: union_find(int n) : data(n, -1) {} int unite(int x, int y) { x = root(x), y = root(y); if(x != y) { if(size(x) < size(y)) swap(x, y); data[x] += data[y]; return data[y] = x; } return -1; } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } bool same(int x, int y) { return root(x) == root(y); } private: vector data; }; int main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; cin >> h >> w; int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--; auto hash = [&](int x, int y){ return x * w + y; }; vector b(h); rep(i,h) cin >> b[i]; union_find uf(h * w); auto ok = [&](int x, int y){ return 0 <= x && x < h && 0 <= y && y < w; }; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; rep(x,h)rep(y,w)rep(d,4) { int nx = x + dx[d], ny = y + dy[d]; if(ok(nx, ny)) { if(abs(b[x][y] - b[nx][ny]) <= 1) uf.unite(hash(x, y), hash(nx, ny)); } int mx = x + dx[d] * 2, my = y + dy[d] * 2; if(ok(nx, ny) && ok(mx, my)) { if(b[x][y] == b[mx][my] && b[x][y] > b[mx][my]) uf.unite(hash(x, y), hash(mx, my)); } } cout << (uf.same(hash(sx, sy), hash(gx, gy)) ? "YES" : "NO") << endl; }