h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
B = [list(map(int, input())) for _ in range(h)]
tf = [[False] * w for _ in range(h)]
tf[sx][sy] = True
stack = [(sx, sy)]

directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
while stack:
    x, y = stack.pop()
    for dx, dy in directions:
        nx = x + dx
        ny = y + dy
        if nx == -1 or nx == h or ny == -1 or ny == w:
            continue
        if abs(B[x][y] - B[nx][ny]) <= 1 and not tf[nx][ny]:
            tf[nx][ny] = True
            stack.append((nx, ny))
        nx2 = nx + dx
        ny2 = ny + dy
        if nx2 == -1 or nx2 == h or ny2 == -1 or ny2 == w:
            continue
        if B[x][y] == B[nx2][ny2] and B[nx][ny] < B[x][y] and not tf[nx2][ny2]:
            tf[nx2][ny2] = True
            stack.append((nx2, ny2))

if tf[gx][gy]:
    print("YES")
else:
    print("NO")