class DisjointSet(object): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n self.num = n # number of disjoint sets def union(self, x, y): self._link(self.find_set(x), self.find_set(y)) def _link(self, x, y): if x == y: return self.num -= 1 if self.rank[x] > self.rank[y]: self.parent[y] = x else: self.parent[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def find_set(self, x): xp = self.parent[x] if xp != x: self.parent[x] = self.find_set(xp) return self.parent[x] def read_data(): h, w = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) bs = [] for _ in range(h): b = input() bs.append(list(map(int, b))) return h, w, sx - 1, sy - 1, gx - 1, gy - 1, bs def solve(h, w, sx, sy, gx, gy, bs): hw = h * w ds = DisjointSet(hw) for x in range(h): for y in range(w): pos = x * w + y b = bs[x][y] if x > 0 and abs(bs[x-1][y] - b) <= 1: ds.union(pos, pos - w) if y > 0 and abs(bs[x][y-1] - b) <= 1: ds.union(pos, pos - 1) if x > 1 and bs[x-2][y] == b and bs[x-1][y] < b: ds.union(pos, pos - w * 2) if y > 1 and bs[x][y-2] == b and bs[x][y-1] < b: ds.union(pos, pos - 2) s = sx * w + sy g = gx * w + gy if ds.find_set(s) == ds.find_set(g): print('YES') else: print('NO') param = read_data() solve(*param)