#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

char G[105][105];
int vis[105][105][7][7];
int H,W;

struct dice{
    int a[6];
    int x,y;
    dice(int x = 0,int y = 0):x(x),y(y){
        a[0] = 1;
        a[1] = 6;
        a[2] = 4;
        a[3] = 3;
        a[4] = 2;
        a[5] = 5;
    }
    int rr(){
        int temp = a[0];
        a[0] = a[2];
        a[2] = a[1];
        a[1] = a[3];
        a[3] = temp;
        y += 1;
        return a[1];
    }
    int lr(){
        int temp = a[0];
        a[0] = a[3];
        a[3] = a[1];
        a[1] = a[2];
        a[2] = temp;
        y -= 1;
        return a[1];
    }
    int ur(){
        int temp = a[0];
        a[0] = a[4];
        a[4] = a[1];
        a[1] = a[5];
        a[5] = temp;
        x -= 1;
        return a[1];

    }
    int dr(){
        int temp = a[0];
        a[0] = a[5];
        a[5] = a[1];
        a[1] = a[4];
        a[4] = temp;
        x += 1;
        return a[1];
    }
    bool mark(){
        //cout << x <<" " <<y << endl;
        if(x < 0 || y < 0 || x >= H || y >= W) return false;
        if( (vis[x][y][a[3]][a[4]]) || (a[1] != G[x][y] - '0') ) return false;
        else{
            vis[x][y][a[3]][a[4]] = 1;
            return true;
        }
    }

};




int main()
{
    cin >> H >> W;
    getchar();
    _for(i,0,H){
        _for(j,0,W){
            char c = getchar();
            G[i][j] = c;
        }
        getchar();
    }
    MEM(vis,0);
    dice d;
    d.mark();
    queue<dice> que;
    que.push(d);
    while(!que.empty()){
        dice dd = que.front();que.pop();
        dice k;

        memcpy(&k,&dd,sizeof(dd));
        k.rr();
        if(k.mark()){
            que.push(k);
            //cout << "ok" << endl;
        }

        memcpy(&k,&dd,sizeof(dd));
        k.lr();
        if(k.mark()){
            que.push(k);
        }

       memcpy(&k,&dd,sizeof(dd));
        k.ur();
           if(k.mark()){
            que.push(k);
        }

        memcpy(&k,&dd,sizeof(dd));
        k.dr();
           if(k.mark()){
            que.push(k);
            //cout << "ok" << endl;
        }
    }

    int OK = 0;
    _for(i,0,7){
        _for(j,0,7){
            if(vis[H-1][W-1][i][j]) OK = 1;
        }
    }
    if(OK) cout <<"YES"<< endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 5300