W,H=gets.split.map &:to_i Sx,Sy,Gx,Gy=gets.split.map{|i|i.to_i-1} T=H.times.map{gets.chomp.chars.map &:to_i} ag=[[Sx,Sy]] def candidate(x,y,ag) h=T[x][y] [[-1,0],[1,0],[0,-1],[0,1]].each{|i,j| k,l=x+i,y+j t=h-T[k][l] ag<<[[k,l]]if k>0&&k0&&l0&&m0&&n0 } end $><<(H*W).times{|i| break(:YES)if ag&[Gx, Gy]!=[] break(:NO)if !(_=ag[i]) candidate(*_,ag)}