#include using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define vv(type, c, m, n, i) vector> c(m, vector(n, i)) #define rep(i,a,n) for(int i=(a), i##_len=(n); ii##_len; --i) #define len(x) ((int)(x).size()) #define mp make_pair #define eb emplace_back #define em emplace #define pb pop_back #define fi first #define se second #define get(a, i) get(a) #define mt make_tuple typedef long long ll; typedef long double ld; typedef vector vi; typedef vector vd; typedef vector vll; typedef vector vs; typedef vector vb; typedef pair pii; #define mini min_element #define maxi max_element #define sum(a, b) accumulate(a, b) #define chmax(a,b) if(ab)a=b #define ce(x, y) (x + y - 1) / y #define print(t) cout << (t) << "\n"; #define printk(v) {rep(i, 0, len(v) - 1) { cout << v[i] << " "; } cout << v.back() << endl;} constexpr int dx[] = {1, 0, -1, 0}; constexpr int dy[] = {0, 1, 0, -1}; string solve() { int h, w; cin >> h >> w; vv(bool, b, h, w, false); vv(int, v, h, w, 0); int sy, sx, gy, gx; cin >> sy>> sx >> gy >> gx; if (sy == gy && sx == gx) return "YES"; --sy; --sx; --gy; --gx; string s; rep(i, 0, h) { cin >> s; rep(j, 0, w) { v[i][j] = s[j] - '0'; } } vector> dp = {tie(sy, sx)}; b[sy][sx] = true; int y, x, ny, nx; while (!dp.empty()) { tie(y, x) = dp.back(); dp.pb(); rep(i, 0, 4) { ny = y + dy[i]; nx = x + dx[i]; if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue; if (!b[ny][nx] && abs(v[ny][nx] - v[y][x]) <= 1) { if (ny == gy && nx == gx) return "YES"; b[ny][nx] = true; dp.eb(tie(ny, nx)); } if (v[ny][nx] >= v[y][x]) continue; ny += dy[i]; nx += dx[i]; if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue; if (!b[ny][nx] && v[ny][nx] == v[y][x]) { if (ny == gy && nx == gx) return "YES"; b[ny][nx] = true; dp.eb(tie(ny, nx)); } } } return "NO"; } int main() { print(solve()); return 0; }