#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; #define rep(i,n) for(ll i=0;i<(n);i++) #define tii tuple #define tiii tuple #define mt make_tuple #define pb push_back #define ALL(a) (a).begin(),(a).end() #define FST first #define SEC second const int INF = (INT_MAX/2); const ll LLINF = (LLONG_MAX/2); const double eps = 1e-5; const double PI = M_PI; #define DEB cerr<<"!"<0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;} bool used[50][50] = {}; vi vec1 ={0,-1,0,1,0}; vi vec2 ={0,2,0,-2,0}; int main(){ int h,w,sx,sy,gx,gy; cin >> h >> w >> sx >> sy >> gx >> gy; sx--,sy--,gx--,gy--; vector vs; rep(i,h){string sin; cin >> sin; vs.pb(sin);} stack s; s.push(tii{sx,sy}); while(!s.empty()){ int x,y; tie(x,y) = s.top(); s.pop(); //SHOW(x,y); //SHOW(vs[x][y],0); used[x][y] = 1; if(gx == x && gy == y){cout <<"YES" << endl; return 0;} rep(i,4){ int nx = vec1[i] + x; int ny = vec1[i+1] + y; if(used[nx][ny] == 0 && nx >= 0 && nx < h && ny >= 0&& ny < w && abs(vs[nx][ny]-vs[x][y]) <= 1) s.push(tii{nx,ny}); } rep(i,4){ int nx = vec2[i] + x; int ny = vec2[i+1] + y; if(used[nx][ny] == 0 && nx >= 0 && nx < h && ny >= 0&& ny < w && abs(vs[nx][ny]-vs[x][y]) <= 0) s.push(tii{nx,ny}); } } cout << "NO" << endl; return 0; }