#!/usr/bin/env python3 import collections DELTA_1 = [(1, 0), (-1, 0), (0, 1), (0, -1)] def can_escape(height, width, start, goal, stage): def out_of_stage(r, c): return r < 0 or r >= height or c < 0 or c >= width visited = collections.defaultdict(bool) visited[start] = True q = collections.deque() q.append(start) while q: r0, c0 = q.popleft() if (r0, c0) == goal: return True for dr, dc in DELTA_1: r, c = r0 + dr, c0 + dc if out_of_stage(r, c): continue elif abs(stage[r][c] - stage[r0][c0]) <= 1 and not visited[(r, c)]: visited[(r, c)] = True q.append((r, c)) r2, c2 = r0 + 2 * dr, c0 + 2 * dc if out_of_stage(r2, c2): continue elif stage[r2][c2] == stage[r0][c0] > stage[r][c]: if not visited[(r2, c2)]: visited[(r2, c2)] = True q.append((r2, c2)) else: return False def main(): height, width = map(int, input().split()) sx, sy, gx, gy = map(lambda x: int(x) - 1, input().split()) start = sx, sy goal = gx, gy stage = [list(map(int, input())) for _ in range(height)] if can_escape(height, width, start, goal, stage): print("YES") else: print("NO") if __name__ == '__main__': main()