#!usr/bin/env python # -*- coding:utf-8 -*- import numpy as np import math import os def move(sx,sy,b,gx,gy,flag): flag[sx-1,sy-1] = 1 #print sx,sy,b[sx-1,sy-1] #print flag if sx+1 <= h and flag[sx,sy-1] == 0: if math.fabs(b[sx-1,sy-1]-b[sx,sy-1]) <= 1: #print 'x+1' if sx+1 == gx and sy == gy: return 1 else: if move(sx+1,sy,b,gx,gy,flag): return 1 if sx-1 > 0 and flag[sx-2,sy-1] == 0: if math.fabs(b[sx-1,sy-1]-b[sx-2,sy-1]) <= 1: #print 'x-1' if sx-1 == gx and sy == gy: return 1 else: if move(sx-1,sy,b,gx,gy,flag): return 1 if sy+1 <= w and flag[sx-1,sy] == 0: if math.fabs(b[sx-1,sy-1]-b[sx-1,sy]) <= 1: #print 'y+1' if sy+1 == gy and sx == gx: return 1 else: if move(sx,sy+1,b,gx,gy,flag): return 1 if sy-1 > 0 and flag[sx-1,sy-2] == 0: if math.fabs(b[sx-1,sy-1]-b[sx-1,sy-2]) <= 1: #print 'y-1' if sx == gx and sy-1 == gy: return 1 else: if move(sx,sy-1,b,gx,gy,flag): return 1 if sx+2 <= h and flag[sx+1,sy-1] == 0: if b[sx-1,sy-1] == b[sx+1,sy-1] and b[sx-1,sy-1] > b[sx,sy-1]: #print 'x+2' if sx+2 == gx and sy == gy: return 1 else: if move(sx+2,sy,b,gx,gy,flag): return 1 if sx-2 > 0 and flag[sx-3,sy-1] == 0: if b[sx-1,sy-1] == b[sx-3,sy-1] and b[sx-1,sy-1] > b[sx-2,sy-1]: #print 'x-2' if sx-2 == gx and sy == gy: return 1 else: if move(sx-2,sy,b,gx,gy,flag): return 1 if sy+2 <= w and flag[sx-1,sy+1] == 0: if b[sx-1,sy-1] == b[sx-1,sy+1] and b[sx-1,sy-1] > b[sx-1,sy]: #print 'y+2' if sx == gx and sy+2 == gy: return 1 else: if move(sx,sy+2,b,gx,gy,flag): return 1 if sy-2 > 0 and flag[sx-1,sy-3] == 0: if b[sx-1,sy-1] == b[sx-1,sy-3] and b[sx-1,sy-1] > b[sx-1,sy-2]: #print 'y-2' if sx == gx and sy-2 == gy: return 1 else: if move(sx,sy-2,b,gx,gy,flag): return 1 return 0 if __name__ == '__main__': h = 5 w = 5 sx = 5 sy = 1 gx = 4 gy = 3 b = [[6,8,2,3,2],[2,4,5,4,3],[0,4,5,2,3],[5,2,6,0,8],[9,8,7,2,8]] S = raw_input().split() SG = raw_input().split() h = int(S[0]) w = int(S[1]) b = np.zeros((h,w)) for i in range(h): B = raw_input() for j in range(w): b[i,j] = int(B[j]) sx = int(SG[0]) sy = int(SG[1]) gx = int(SG[2]) gy = int(SG[3]) #print b flag = np.zeros((h,w)) if move(sx,sy,b,gx,gy,flag): print 'YES' else: print 'NO' print '\r'