#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <unordered_map>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
#define Range(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;

const pii four_Dir[4] = { //四方向
	{ 0 ,1 },
	{ -1 ,0 },{ 1 ,0 },
	{ 0 ,-1 }
};

int main() {
	int h, w;
	pii s, g;
	scanf("%d %d %d %d %d %d", &h, &w, &s.second, &s.first, &g.second, &g.first);
	s.first--;
	s.second--;
	g.first--;
	g.second--;
	vector<vector<int>> m(w, vector<int>(h));
	REP(i, h) {
		scanf("%*c");
		REP(j, w) {
			char c;
			scanf("%c", &c);
			m[j][i] = c - '0';
		}
	}

	queue<pii> que;
	map<pii,bool> al;
	que.push(s);
	while (que.size()) {
		auto cur = que.front();
		que.pop();
		if (cur == g) {
			printf("YES\n");
			return 0;
		}
		if (al[cur]) continue;
		al[cur] = true;

		REP(i, 4) {
			pii next = {cur.first + four_Dir[i].first, cur.second + four_Dir[i].second};
			if (!al[next] && Range(next.first, 0, w-1) && Range(next.second, 0, h-1)) {
				if (abs(m[cur.first][cur.second] - m[next.first][next.second]) <= 1) {
					que.push(next);
				}
			}
			next = { next.first + four_Dir[i].first, next.second + four_Dir[i].second };
			if (!al[next] && Range(next.first, 0, w-1) && Range(next.second, 0, h-1)) {
				if (m[cur.first][cur.second] > m[next.first - four_Dir[i].first][next.second - four_Dir[i].second] && m[cur.first][cur.second] == m[next.first][next.second]) {
					que.push(next);
				}
			}
		}
	}
	printf("NO\n");
	return 0;
}