#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

struct dice{
    ll x, y, z;
};

dice roll(dice d, ll dir){
    ll x = d.x, y = d.y, z = d.z;
    if(dir == 0) d.x = y, d.y = 7 - x;
    if(dir == 1) d.x = z, d.z = 7 - x;
    if(dir == 2) d.x = 7 - y, d.y = x;
    if(dir == 3) d.x = 7 - z, d.z = x;
    return d;
}

typedef pair<int,int> pos;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int main(){
   int h,w; scanf("%d%d",&h,&w);
   string s[110]; rep(i,0,h)cin>>s[i];
   queue<pair<pos,dice>> que; que.push({{0,0},{6,2,3}});
   bool used[110][110]={}; used[0][0]=1;
   while(!que.empty()){
      auto p=que.front(); que.pop();
      pos xy=p.first; dice d=p.second;
      if(s[xy.first][xy.second]!=(d.x+'0'))continue;
      if(xy.first==h-1&&xy.second==w-1){puts("YES"); return 0;}
      rep(i,0,4){
         int nx=xy.first+dx[i],ny=xy.second+dy[i];
         if(nx<0||nx>=h||ny<0||ny>=w||used[nx][ny])continue;
         que.push({{nx,ny},roll(d,i)}); used[nx][ny]=1;
      }
   } puts("NO");
   return 0;
}
