#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } vector dr = {1, 0, -1, 0}; vector dc = {0, 1, 0, -1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int h, w; cin >> h >> w; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; vector> g(h, vector(w)); rep(i, h) { string s; cin >> s; rep(j, w) g[i][j] = s[j] - '0'; } int INF = INT_MAX / 10; vector> d(h, vector(w, INF)); d[sx][sy] = 0; queue qr, qc; qr.push(sx); qc.push(sy); while(!qr.empty()){ int r = qr.front(), c = qc.front(); qr.pop(); qc.pop(); if(r == gx && c == gy){ cout << "YES" << endl; exit(0); } rep(i, 4){ int nr = r + dr[i]; int nc = c + dc[i]; if(0 <= nr && nr < h && 0 <= nc && nc < w){ if(d[nr][nc] > d[r][c] + 1 && abs(g[nr][nc] - g[r][c]) <= 1){ d[nr][nc] = d[r][c] + 1; qr.push(nr); qc.push(nc); } } nr += dr[i]; nc += dc[i]; if(0 <= nr && nr < h && 0 <= nc && nc < w){ if(d[nr][nc] > d[r][c] + 1 && abs(g[nr][nc] - g[r][c]) == 0 && g[nr-dr[i]][nc-dc[i]] < g[r][c]){ d[nr][nc] = d[r][c] + 1; qr.push(nr); qc.push(nc); } } } } cout << "NO" << endl; }