#include "stdio.h"
#include "queue"
#include "utility"
#include "math.h"

using namespace std;
typedef pair<int, int>P;
P now;
P goal;
P box;
int H, W;
char hei[51][51];
int height[51][51];
int dx[8] = { 1,0,-1,0,2,0,-2,0 };
int dy[8] = { 0,-1,0,1,0,-2,0,2 };
queue <P> Q;
int dis[51][51];

int main() {
	scanf("%d %d", &H, &W);
	scanf("%d %d %d %d", &now.first, &now.second, &goal.first, &goal.second);
	for (int i = 1; i <= H; i++) {
		scanf("%s", hei[i]);
	}
	for (int i = 1; i <= H; i++) {
		for (int j = W; j >= 1; j--) {
			hei[i][j] = hei[i][j - 1];
			height[i][j] = hei[i][j] - '0';
			//printf("%d", height[i][j]);
		}
	}
	Q.push(now);
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			dis[i][j] = 10000;
		}
	}
	dis[now.first][now.second] = 0;
	while (!Q.empty()) {
		now = Q.front();
	//	printf("%d %dを調べる\n", now.first, now.second);
		for (int i = 0; i < 8; i++) {
			if (now.first + dy[i] >= 1 && now.first + dy[i] <= H&&now.second + dx[i] >= 1 && now.second + dx[i] <= W) {
				if (i < 4) {
					if (abs(height[now.first][now.second] - height[now.first + dy[i]][now.second + dx[i]])<2) {
						if (dis[now.first][now.second] + 1 < dis[now.first + dy[i]][now.second + dx[i]]) {
							dis[now.first + dy[i]][now.second + dx[i]] = dis[now.first][now.second] + 1;
							box.first = now.first + dy[i];
							box.second = now.second + dx[i];
							Q.push(box);
						}
					}
				}
				else {
					if (height[now.first][now.second] == height[now.first + dy[i]][now.second + dx[i]]) {
						if (height[now.first][now.second] > height[now.first + dy[i] / 2][now.second + dx[i] / 2]) {
							if (dis[now.first][now.second] + 1 < dis[now.first + dy[i]][now.second + dx[i]]) {
								dis[now.first + dy[i]][now.second + dx[i]] = dis[now.first][now.second] + 1;
								box.first = now.first + dy[i];
								box.second = now.second + dx[i];
								Q.push(box);
							}
						}
					}
				}
			}
		}
		Q.pop();
	}
	if (dis[goal.first][goal.second] != 10000)printf("YES\n");
	else printf("NO\n");
	return 0;
}