#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl #define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;} #define printP(p) cout << p.first << " " << p.second << endl #define printVP(vp) for(auto&& p : vp) printP(p); typedef long long ll; typedef pair Pii; typedef tuple TUPLE; typedef vector vi; typedef vector vvi; typedef vector vvvi; typedef vector vp; const int inf = 1e9; const int mod = 1e9 + 7; int H, W; int sx, sy, gx, gy; vector s; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; bool inside(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } int bfs() { queue> que; que.emplace(sx, sy); vector> d(H, vector(W, inf)); d[sx][sy] = 0; while (!que.empty()) { int x, y; tie(x, y) = que.front(); que.pop(); if (x == gx && y == gy) break; rep(k, 4) { int nx = x + dx[k], ny = y + dy[k]; int nnx = x + 2 * dx[k], nny = y + 2 * dy[k]; if (inside(nx, ny) && d[nx][ny] == inf && abs(s[nx][ny] - s[x][y]) <= 1) { d[nx][ny] = d[x][y] + 1; que.emplace(nx, ny); } if (inside(nnx, nny) && d[nnx][nny] == inf && s[nnx][nny] == s[x][y] && s[nx][ny] < s[x][y]) { d[nnx][nny] = d[x][y] + 1; que.emplace(nnx, nny); } } } return (d[gx][gy] == inf ? -1 : d[gx][gy]); } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> H >> W; cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--; s.resize(H); rep(i, H) cin >> s[i]; cout << (bfs() != -1 ? "YES" : "NO") << endl; }