#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


struct Die{
  array<int, 6> s;
  int &top()   {return s[0];}
  int &south() {return s[1];}
  int &east()  {return s[2];}
  int &west()  {return s[3];}
  int &north() {return s[4];}
  int &bottom(){return s[5];}
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    string b("EWNSRL");
    int v[6][4]={{0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2}};
    for(int k=0;k<6;k++){
      if(b[k]!=c) continue;
      int t=s[v[k][0]];
      s[v[k][0]]=s[v[k][1]];
      s[v[k][1]]=s[v[k][2]];
      s[v[k][2]]=s[v[k][3]];
      s[v[k][3]]=t;
    }
  }
  using ll = long long;
  ll hash(){
    ll res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
  bool operator==(const Die &d) const{
    for(int i=0;i<6;i++) if(s[i]!=d.s[i]) return 0;
    return 1;
  }
};

vector<Die> makeDice(Die d){
  vector<Die> res;
  for(int i=0;i<6;i++){
    Die t(d);
    if(i==1) t.roll('N');
    if(i==2) t.roll('S');
    if(i==3) t.roll('S'),t.roll('S');
    if(i==4) t.roll('L');
    if(i==5) t.roll('R');
    for(int k=0;k<4;k++){
      res.push_back(t);
      t.roll('E');
    }
  }
  return res;
}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
int dp[100][200][200];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w;
  cin>>h>>w;
  vector<string> ss(h);
  for(int i=0;i<h;i++) cin>>ss[i];

  Die d;
  d.top()='1';
  d.bottom()='6';
  d.north()='5';
  d.south()='2';
  d.east()='3';
  d.west()='4';

  auto ds=makeDice(d);
  map<array<int, 6>, int> idx;
  for(int i=0;i<(int)ds.size();i++)
    idx[ds[i].s]=i;

  memset(dp,0,sizeof(dp));
  using T = tuple<int, int, int>;
  queue<T> que;

  dp[idx[d.s]][0][0]=1;
  que.emplace(idx[d.s],0,0);

  while(!que.empty()){
    int k,i,j;
    tie(k,i,j)=que.front();que.pop();
    if(i==h-1 and j==w-1) drop("YES");
    d=ds[k];

    // cout<<k<<" "<<i<<" "<<j<<endl;

    if(i+1<h){
      int ni=i+1,nj=j;
      Die nd(d);
      nd.roll('S');
      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.s]][ni][nj]){
        dp[idx[nd.s]][ni][nj]=1;
        que.emplace(idx[nd.s],ni,nj);
      }
    }
    if(i-1>=0){
      int ni=i-1,nj=j;
      Die nd(d);
      nd.roll('N');
      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.s]][ni][nj]){
        dp[idx[nd.s]][ni][nj]=1;
        que.emplace(idx[nd.s],ni,nj);
      }
    }

    if(j+1<w){
      int ni=i,nj=j+1;
      Die nd(d);
      nd.roll('E');
      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.s]][ni][nj]){
        dp[idx[nd.s]][ni][nj]=1;
        que.emplace(idx[nd.s],ni,nj);
      }
    }
    if(j-1>=0){
      int ni=i,nj=j-1;
      Die nd(d);
      nd.roll('W');
      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.s]][ni][nj]){
        dp[idx[nd.s]][ni][nj]=1;
        que.emplace(idx[nd.s],ni,nj);
      }
    }
  }

  drop("NO");
  return 0;
}



Measured memory_bytes: 18892