#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<60; const ll MOD = 1000000007; const double EPS = 1e-10; int h, w; int sx, sy, gx, gy; string maps[50]; bool done[50][50]; int main() { cin >> h >> w; cin >> sy >> sx >> gy >> gx; sx--; sy--; gx--; gy--; REP(i, h) cin >> maps[i]; queue que; que.push(pii(sx, sy)); while (!que.empty()) { int x = que.front().first; int y = que.front().second; que.pop(); if (done[y][x]) continue; done[y][x] = true; int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; REP(t, 2) { REP(i, 4) { int nx = x + dx[i] * (t + 1); int ny = y + dy[i] * (t + 1); if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue; if (done[ny][nx]) continue; if (t == 0) { if (abs(maps[y][x] - maps[ny][nx]) > 1) continue; } else { if (maps[y][x] != maps[ny][nx] || maps[y + dy[i]][x + dx[i]] > maps[y][x]) continue; } que.push(pii(nx, ny)); } } } puts(done[gy][gx] ? "YES" : "NO"); return 0; }