#include using namespace std; #define rep(i,n) for (int i = 0; i< (n); ++i) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) (x).begin(), (x).end() #define fore(i, a) for(auto &i:a) using ll = long long; int main() { ll h, w, sx, sy, gx, gy; cin >> h >> w >> sx >> sy >> gx >> gy; sx--;sy--;gx--;gy--; vector> height(h, vector(w, 0)); char temp; rep(i, h)rep(j, w){ cin >> temp; height[i][j] = temp - '0'; } vector> is_reachalbe(h, vector(w, false)); queue> q; q.push({sx,sy}); is_reachalbe[sx][sy] = true; vector di = {1, 0, -1, 0}; vector dj = {0, 1, 0, -1}; auto hantei = [&](ll x, ll y){ return x >= 0 && x < h && y >= 0 && y < w; }; while(!q.empty()){ auto[x, y] = q.front(); q.pop(); ll nx, ny; rep(d, 4){ nx = x+di[d];ny = y+dj[d]; if(!hantei(nx,ny) || is_reachalbe[nx][ny]) continue; if(abs(height[x][y] - height[nx][ny]) <= 1){ is_reachalbe[nx][ny] = true; q.push({nx,ny}); } } ll ax, ay; rep(d, 4){ nx = x+di[d]*2;ny = y+dj[d]*2; ax = x+di[d];ay = y+dj[d]; if(!hantei(nx,ny) || is_reachalbe[nx][ny]) continue; if(height[x][y] == height[nx][ny] && height[ax][ay] < height[x][y]){ is_reachalbe[nx][ny] = true; q.push({nx,ny}); } } } if(is_reachalbe[gx][gy])cout << "YES" << endl; else cout << "NO" << endl; }