#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w;
int sx, sy, gx, gy;
string b[50];
bool reached[50][50];

int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

signed main()
{
	cin >> h >> w;
	cin >> sy >> sx >> gy >> gx;
	sx--; sy--; gx--; gy--;
	rep(i,h) cin >> b[i];

	//rep(i,h) cout << b[i] << endl;

	queue<P> que;
	que.push(P(sx, sy));
	reached[sy][sx] = true;

	/*
	rep(i,h) {
		rep(j,w) {
			cout << b[i][j];
		}
		cout << endl;
	}
	*/

	while (que.size()) {
		P p = que.front(); que.pop();

		//cout << "x = " << p.first << " : y = " << p.second << endl;

		if (p.first == gx && p.second == gy) {
			cout << "YES" << endl;
			return 0;
		}
		rep(i,4) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			//printf("b[%d][%d] = %c\n", ny, nx, b[ny][nx]);
			if (0 <= nx && nx < w && 0 <= ny && ny < h && !reached[ny][nx] && (abs((b[ny][nx] - '0') - (b[p.second][p.first] - '0')) <= 1)) {
				//cout << "TTTTTTTTTTT" << endl;
				que.push(P(nx, ny));
				reached[ny][nx] = true;
			}
			if (0 <= nx && nx < w && 0 <= ny &&  ny < h && b[ny][nx] < b[p.second][p.first]) {
				nx += dx[i];
				ny += dy[i];
				if (0 <= nx && nx < w && 0 <= ny &&  ny < h && !reached[ny][nx] && b[ny][nx] == b[p.second][p.first]) {
					que.push(P(nx, ny));
					reached[ny][nx] = true;
				}
			}
		}
	}

	cout << "NO" << endl;
}