// I SEint YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
string d[110];
bool used[110][110]={};
signed main(){
  init_io();
  int h,w;
  int arr[]={6,3,1,4},idx;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    cin >> d[i];
    if(i%4==0) idx = 0;
    else idx = 2;
    for(int j=0;j<w;j++){
      if(i%2==0){
        if((d[i][j]-'0')!=arr[idx]){
          d[i][j]='#';
        }
        if(i%4==0) idx = (idx+1)%4;
        else idx = (idx+3)%4;
      }else{
        if((i+1)%4==0&&(d[i][j]-'0')!=5){
          d[i][j] = '#';
        }else if((i+1)%4!=0&&(d[i][j]-'0')!=2){
          d[i][j] = '#';
        }
      }
    }
  }
  queue<pair<int,int> > que;
  que.push(pair<int,int>(0,0));
  int vx[]={1,0,-1,0},vy[]={0,1,0,-1};
  while(!que.empty()){
    pair<int,int> tmp = que.front();
    que.pop();
    int x = tmp.first, y=tmp.second;
    if(used[x][y]) continue;
    used[x][y] = true;
    for(int i=0;i<4;i++){
      int nx = x + vx[i];
      int ny = y + vy[i];
      if(nx>=0&&ny>=0&&nx<h&&ny<w){
        if(d[nx][ny]!='#'){
          que.push(pair<int,int>(nx,ny));
        }
      }
    }
  }
  if(used[h-1][w-1]){
    cout <<"YES\n";
  }else{
    cout <<"NO\n";
  }
}

