#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; int h, w; int sx, sy, gx, gy; vectormp(55); int memo[55][55]; int used[55][55]; int check1(int x1,int y1,int x2,int y2) { int h1 = mp[y1][x1] - '0'; int h2 = mp[y2][x2] - '0'; if (abs(x1 - x2)+abs(y1 - y2) == 1) { if (abs(h1 - h2) <= 1)return true; }else { if (abs(x1 - x2) == 2) { int h3 = mp[y2][(x1+x2)/2] - '0'; if (h1 == h2 && h1 > h3)return true; } else { int h4 = mp[(y1+y2)/2][x2] - '0'; if (h1 == h2 && h1 > h4)return true; } } return false; } int dfs(int x,int y) { if (x == gx && y == gy)return true; if (memo[y][x] != -1)return memo[y][x]; int dx[8] = {-1,0,1,0,-2,0,2,0}; int dy[8] = {0,1,0,-1,0,2,0,-2}; int ret = 0; rep(i, 0, 8) { int x_ = x + dx[i]; int y_ = y + dy[i]; if (0 <= y_ && y_ <= h - 1 && 0 <= x_ && x_ <= w - 1 && used[y_][x_] == 0) { if (check1(x, y, x_, y_)) { used[y_][x_] = 1; if (dfs(x_, y_))ret = 1; } } } return memo[y][x] = ret; } int main() { cin >> h >> w; cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--; swap(sx, sy); swap(gx, gy); rep(i, 0, h) { cin >> mp[i]; } memset(memo, -1, sizeof(memo)); used[sy][sx] = 1; if (dfs(sx,sy))cout << "YES" << endl; else cout << "NO" << endl; return 0; }