h,w=gets.split.map(&:to_i) sx,sy,gx,gy=gets.split.map{|s|s.to_i-1} maze=h.times.map{gets.chomp.bytes.to_a} init_state=[sx,sy] q=[init_state] visited={} until q.empty? curr_state=q.shift next if visited[curr_state] visited[curr_state]=true if curr_state==[gx,gy] puts "YES" exit end height=maze.dig(*curr_state) x,y=curr_state [[1,0],[0,1],[-1,0],[0,-1]].each{|dx,dy| nx,ny=x+dx,y+dy next unless (0...h)===nx next unless (0...w)===ny next_state=[nx,ny] next if (maze.dig(*next_state)-height).abs>1 q.push next_state } [[2,0],[0,2],[-2,0],[0,-2]].each{|dx,dy| nx,ny=x+dx,y+dy next unless (0...h)===nx next unless (0...w)===ny next_state=[nx,ny] next unless maze.dig(*next_state)==height middle=[x+dx/2,y+dy/2] next if maze.dig(*middle)>=height q.push next_state } end puts "NO"