#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

vector<int> dr = {1, 0, -1, 0};
vector<int> 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<vector<int>> g(h, vector<int>(w));
	rep(i, h) {
		string s;
		cin >> s;
		rep(j, w) g[i][j] = s[j] - '0';
	}

	int INF = INT_MAX / 10;
	vector<vector<int>> d(h, vector<int>(w, INF));
	d[sx][sy] = 0;

	queue<int> 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;

}