import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static int[][] move_dirs = { {0, 1}, {0, -1}, { 1, 0}, {-1, 0} }; public static boolean in_range(int x, int y, int w, int h){ return 0 <= x && x < w && 0 <= y && y < h; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int h = sc.nextInt(); final int w = sc.nextInt(); final int sy = sc.nextInt() - 1; final int sx = sc.nextInt() - 1; final int gy = sc.nextInt() - 1; final int gx = sc.nextInt() - 1; int[][] heights = new int[h][w]; for(int i = 0; i < h; i++){ final char[] in = sc.next().toCharArray(); for(int j = 0; j < w; j++){ heights[i][j] = Character.getNumericValue(in[j]); } } boolean[][] visited = new boolean[h][w]; LinkedList x_queue = new LinkedList(); LinkedList y_queue = new LinkedList(); x_queue.add(sx); y_queue.add(sy); visited[sy][sx] = true; while(!x_queue.isEmpty()){ final int x = x_queue.poll(); final int y = y_queue.poll(); for(int[] move : move_dirs){ final int nx = x + move[0]; final int ny = y + move[1]; final int nnx = x + move[0] * 2; final int nny = y + move[1] * 2; if(!in_range(nx, ny, w, h)){ continue; } if(!visited[ny][nx] && Math.abs(heights[y][x] - heights[ny][nx]) <= 1){ visited[ny][nx] = true; x_queue.add(nx); y_queue.add(ny); } if(!in_range(nnx, nny, w, h)){ continue; } if(!visited[nny][nnx] && heights[nny][nnx] == heights[y][x] && heights[ny][nx] < heights[y][x]){ visited[nny][nnx] = true; x_queue.add(nnx); y_queue.add(nny); } } } System.out.println(visited[gy][gx] ? "YES" : "NO"); } }