import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class No424 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); Place start = new Place(sc.nextInt()-1,sc.nextInt()-1); Place goal = new Place(sc.nextInt()-1,sc.nextInt()-1); int map[][] = new int[h][w]; for(int i = 0;i < h;i++) { String s = sc.next(); for(int j = 0;j < w;j++) { map[i][j] = Integer.parseInt("" + s.charAt(j)); } } int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; int dx2[] = {2,0,-2,0}; int dy2[] = {0,2,0,-2}; int mapprime[][] = new int[h][w]; //0なら到達不可能,1なら到達可能 mapprime[start.x][start.y] = 1; Queue que = new LinkedList(); que.offer(start); while(que.size() > 0) { Place cplace = que.poll(); for(int i = 0;i < 4;i++) { int x1 = cplace.x + dx[i]; int y1 = cplace.y + dy[i]; int x2 = cplace.x + dx2[i]; int y2 = cplace.y + dy2[i]; if(x1 >= 0 && x1 < h && y1 >= 0 && y1 < w && mapprime[x1][y1] == 0) { if(Math.abs(map[cplace.x][cplace.y] - map[x1][y1]) == 1 || Math.abs(map[cplace.x][cplace.y] - map[x1][y1]) == 0) { mapprime[x1][y1] = 1; que.offer(new Place(x1,y1)); } } if(x2 >= 0 && x2 < h && y2 >= 0 && y2 < w && mapprime[x2][y2] == 0) { if(map[cplace.x][cplace.y] == map[x2][y2] && map[x2][y2] > map[x1][y1]) { mapprime[x2][y2] = 1; que.offer(new Place(x2,y2)); } } } } if(mapprime[goal.x][goal.y] == 1) { System.out.println("YES"); }else { System.out.println("NO"); } } } class Place{ int x; //縦方向 int y; //横方向 Place(int x,int y){ this.x = x; this.y = y; } }