# https://yukicoder.me/problems/no/1219 from collections import deque def main(): h, w = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) B = [] for _ in range(h): row = input() row = [int(x) for x in row] B.append(row) sx -= 1 sy -= 1 gx -= 1 gy -= 1 dists = [[False] * w for _ in range(h)] dists[sx][sy] = True queue = deque() queue.append((sx, sy)) while len(queue) > 0: x, y = queue.popleft() height = B[x][y] for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx = x + dx ny = y + dy if nx < 0 or nx >= h or ny < 0 or ny >= w: continue if abs(B[nx][ny] - height) <= 1 and dists[nx][ny] == False: dists[nx][ny] = True queue.append((nx, ny)) for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx = x + 2 * dx ny = y + 2 * dy if nx < 0 or nx >= h or ny < 0 or ny >= w: continue nx1 = x + dx ny1 = y + dy if height == B[nx][ny] and B[nx1][ny1] < height: if dists[nx][ny] == False: dists[nx][ny] = True queue.append((nx, ny)) if dists[gx][gy]: print("YES") else: print("NO") if __name__ == "__main__": main()