from collections import deque

H, W = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
m = []
for i in range(H):
    m.append(input())

q = deque()
dis = [[-1]*W for _ in range(H)]
dis[sx-1][sy-1] = 0
q.append((sx-1, sy-1))
xx = [1, 0, -1, 0]
pp = [2, 0, -2, 0]
yy = [0, 1, 0, -1]
qq = [0, 2, 0, -2]

while q:
    x, y = q.popleft()
    for px, py in zip(xx, yy):
        cx = x+px
        cy = y+py
        if 0<=cx<H and 0<=cy<W and dis[cx][cy] == -1:
            if abs(int(m[x][y])-int(m[cx][cy])) <= 1:
                dis[cx][cy] = dis[x][y] + 1
                q.append((cx, cy))
    for px, py in zip(pp, qq):
        cx = x+px
        cy = y+py
        if 0<=cx<H and 0<=cy<W and dis[cx][cy] == -1:
            if int(m[cx][cy]) == int(m[x][y]) and int(m[(cx+x)//2][(cy+y)//2]) < int(m[x][y]):
                dis[cx][cy] = dis[x][y]+1
                q.append((cx, cy))
if dis[gx-1][gy-1] == -1:
    print('NO')
else:
    print('YES')