#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool dp[51][51];
int g[51][51];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    REP(i,51){
        REP(j,51){
            dp[i][j]=false;
        }
    }
    int h,w,sx,sy,gx,gy;
    cin>>h>>w>>sx>>sy>>gx>>gy;
    REP(i,h){
        string s;
        cin>>s;
        REP(j,w){
            g[i+1][j+1]=s[j]-'0';
        }
    }
    queue<pair<int,int> > que;
    que.push(make_pair(sx,sy));
    dp[sx][sy]=true;
    bool check=false;
    while(!que.empty()){
        pair<int,int> p=que.front();
        if(p.first==gx&&p.second==gy){
           check=true;
           break;
        }
        que.pop();
        REP(i,4){
            int x=p.first+dx[i];
            int y=p.second+dy[i];
            if(x>0&&y>0&&x<=h&&y<=w){
                 if(dp[x][y]==false&&abs(g[p.first][p.second]-g[x][y])<=1){
                    dp[x][y]=true;
                    que.push(make_pair(x,y));
                 }
            }
            
            x+=dx[i];
            y+=dy[i];
            if(x>0&&y>0&&x<=h&&y<=w){
                 if(dp[x][y]==false&&g[p.first][p.second]==g[x][y]&&g[x][y]>=g[(x+p.first)/2][(y+p.second)/2]){
                    dp[x][y]=true;
                    que.push(make_pair(x,y));
                 }
            }
        }
    }
    if(check==true){
       cout<<"YES"<<endl;
    }else{
       cout<<"NO"<<endl;
    }
}