from collections import deque int1 = lambda x: int(x) - 1 H, W = map(int, input().split()) Sx, Sy, Gx, Gy = map(int1, input().split()) B = [[int(x) for x in input()] for _ in range(H)] # bfs d = deque([(Sx, Sy)]) visited = set(d) while d: x, y = d.popleft() for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)): if 0 <= x + dx < H and 0 <= y + dy < W and (x + dx, y + dy) not in visited: if abs(B[x + dx][y + +dy] - B[x][y]) <= 1: d.append(((x + dx, y + dy))) visited.add((x + dx, y + dy)) for dx, dy in ((0, 2), (2, 0), (0, -2), (-2, 0)): if 0 <= x + dx < H and 0 <= y + dy < W and (x + dx, y + dy) not in visited: if B[x + dx][y + +dy] == B[x][y]: d.append(((x + dx, y + dy))) visited.add((x + dx, y + dy)) print('YES' if (Gx, Gy) in visited else 'NO')