from collections import deque import bisect import math from decimal import Decimal import heapq import sys sys.setrecursionlimit(10**9) h,w = map(int,input().split()) sx,sy,ex,ey = map(int,input().split()) bb = [list(input()) for i in range(h)] b = [[1 for i in range(w+1)] for j in range(h+1)] for i in range(h): for j in range(w): b[i+1][j+1] = int(bb[i][j]) q = deque([]) d = [[1 for i in range(w+1)] for j in range(h+1)] d[sx][sy] = 0 q.append((sx,sy)) lis = [[1,0],[-1,0],[0,1],[0,-1]] while q: (x,y) = q.popleft() if x == ex and y == ey: print("YES") exit() # 1masu for xx,yy in lis: if 1 <= x + xx <= h and 1 <= y + yy <= w: if abs(b[x+xx][y+yy] - b[x][y]) <= 1: if d[x+xx][y+yy] == 1: d[x+xx][y+yy] = 0 q.append((x+xx,y+yy)) # 2masu for xx,yy in lis: if 1 <= x + 2*xx <= h and 1 <= y + 2*yy <= w: if b[x+xx][y+yy] <= b[x][y] and b[x+2*xx][y+2*yy] == b[x][y]: if d[x+2*xx][y+2*yy] == 1: d[x+2*xx][y+2*yy] = 0 q.append((x+2*xx,y+2*yy)) print("NO")