from collections import deque

def bfs(sx, sy):
    queue = deque([])
    queue.append((sx, sy))
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    visited[sx][sy] = 1
    
    while len(queue) > 0:
        cx, cy = queue.popleft()
        
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nx, ny = cx + dx, cy + dy
            
            if 0 <= nx < h and 0 <= ny < w:
                if abs(S[cx][cy] - S[nx][ny]) <= 1 and visited[nx][ny] == -1:
                    visited[nx][ny] = 1
                    queue.append((nx, ny))
        
        for dx, dy in [(-2, 0), (2, 0), (0, -2), (0, 2)]:
            nx, ny = cx + dx, cy + dy
            
            if 0 <= nx < h and 0 <= ny < w:
                mx, my = (nx + cx) // 2, (ny + cy) // 2
                
                if S[cx][cy] == S[nx][ny] and S[cx][cy] > S[mx][my] and visited[nx][ny] == -1:
                    visited[nx][ny] = 1
                    queue.append((nx, ny))
    
    return visited
    
h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(h)]
visited = bfs(sx-1, sy-1)

if visited[gx-1][gy-1] == 1:
    print('YES')
else:
    print('NO')