from collections import deque
H,W = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
B = [list(str(input())) for _ in range(H)]
visited = [[0 for _ in range(W)] for _ in range(H)]
visited[sx][sy] = 1
que = deque([(sx,sy,int(B[sx][sy]))])
move = [(-1,0),(0,-1),(1,0),(0,1)]
while que:
    x,y,z = que.pop()
    if x == gx and y == gy:
        print("YES")
        exit()
    for i,j in move:
        h,w = x+i,y+j
        if 0 <= h < H and 0 <= w < W:
            if visited[h][w] == 0:
                if int(B[h][w])-1 <= z <= int(B[h][w])+1:
                    visited[h][w] = 1
                    que.append((h,w,int(B[h][w])))
                if z > int(B[h][w]):
                    h += i
                    w += j
                    if 0 <= h < H and 0 <= w < W:
                        if visited[h][w] == 0:
                            if z == int(B[h][w]):
                                visited[h][w] = 1
                                que.append((h,w,int(B[h][w])))

print("NO")