#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int h, w;
    cin >> h >> w;

    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sx--;
    sy--;
    gx--;
    gy--;

    vvi b(h, vi(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;
            b[i][j] = c - '0';
        }
    }

    vvi dist(h, vi(w, 1e9));
    dist[sx][sy] = 0;
    using ii = pair<int, int>;
    queue<ii> que;
    que.push(ii(sx, sy));
    auto ok = [&](int x, int y) {
        return 0 <= x && x < h && 0 <= y && y < w;
    };

    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    while (que.size()) {
        ii t = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 2; j++) {
                int x = t.first + dx[i] * j;
                int y = t.second + dy[i] * j;
                if (ok(x, y)) {
                    if (j == 2) {
                        if (b[t.first][t.second] != b[x][y]) continue;
                        if (!(b[t.first + dx[i]][t.second + dy[i]] < b[t.first][t.second])) continue;
                    } else {
                        if (abs(b[t.first][t.second] - b[x][y]) > 1) continue;
                    }
                    if (dist[t.first][t.second] + 1 < dist[x][y]) {
                        dist[x][y] = dist[t.first][t.second] + 1;
                        que.push(ii(x, y));
                    }
                }
            }
        }
    }

    if (dist[gx][gy] != 1e9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}