import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; void solve() throws IOException { h = ni(); w = ni(); sx = ni() - 1; sy = ni() - 1; gx = ni() - 1; gy = ni() - 1; b = new int[h][w]; for (int i = 0; i < h; i++) { b[i] = ns().chars().map(c -> c - '0').toArray(); } used = new boolean[h][w]; out.println(rec(sx, sy) ? "YES" : "NO"); } int h, w, sx, sy, gx, gy; int[][] b; boolean[][] used; int[] dx = {1, 0, -1, 0}; int[] dy = {0, 1, 0, -1}; int[] dx2 = {2, 0, -2, 0}; int[] dy2 = {0, 2, 0, -2}; boolean rec(int i, int j) { if (used[i][j]) return false; used[i][j] = true; if (i == gx && j == gy) { return true; } for (int k = 0; k < 4; k++) { if (isin(i + dx[k], j + dy[k]) && Math.abs(b[i][j] - b[i + dx[k]][j + dy[k]]) <= 1 && rec(i + dx[k], j + dy[k])) { return true; } if (isin(i + dx2[k], j + dy2[k]) && b[i][j] == b[i + dx2[k]][j + dy2[k]] && rec(i + dx2[k], j + dy2[k])) { return true; } } return false; } boolean isin(int i, int j) { return 0 <= i && i <= h - 1 && 0 <= j && j <= w - 1; } String ns() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine(), " "); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String[] nsa(int n) throws IOException { String[] res = new String[n]; for (int i = 0; i < n; i++) { res[i] = ns(); } return res; } int[] nia(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = ni(); } return res; } long[] nla(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nl(); } return res; } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); tok = new StringTokenizer(""); Main main = new Main(); main.solve(); out.close(); } }