#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int h,w;cin >> h >> w;
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    sx--,sy--,gx--,gy--;
    vector<string> b(h);
    for(int i=0;i<h;i++){
        cin >> b[i];
    }
    vector<vector<bool>> re(h,vector<bool>(w));
    queue<pair<int,int>> q;
    q.push({sx,sy});
    re[sx][sy]=true;
    while(!q.empty()){
        int u=q.front().first,v=q.front().second;
        q.pop();
        int s=b[u][v]-'0';
        for(int i=0;i<4;i++){
            int x=u+dx[i],y=v+dy[i];
            int t=b[x][y]-'0';
            if(x>=0&&x<=h-1&&y>=0&&y<=w-1){
                if(!re[x][y]&&abs(t-s)<=1){
                    q.push({x,y});
                    re[x][y]=true;
                }
            }
        }
        for(int i=0;i<4;i++){
            int x=u+dx[i]*2,y=v+dy[i]*2;
            if(x>=0&&x<=h-1&&y>=0&&y<=w-1){
                int t=b[x][y]-'0';
                int w=b[(u+x)/2][(v+y)/2]-'0';
                if(!re[x][y]&&s==t&&w<s){
                    q.push({x,y});
                    re[x][y]=true;
                }
            }
        }
    }
    if(re[gx][gy]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}