#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

struct Dice
{
    //int x, y;
    int l, r, f, b, d, u;

    void RollN()
    {
        //  --y;
        int buff = d;
        d = f;
        f = u;
        u = b;
        b = buff;
    }

    void RollS()
    {
        // ++y;
        int buff = d;
        d = b;
        b = u;
        u = f;
        f = buff;
    }

    void RollL() // ----->
    {
        int buff = f;
        f = l;
        l = b;
        b = r;
        r = buff;
    }

    void RollR() // <------
    {
        int buff = f;
        f = r;
        r = b;
        b = l;
        l = buff;
    }

    void RollE() // .o -> o.
    {
        // --x;
        int buff = d;
        d = l;
        l = u;
        u = r;
        r = buff;
    }


    void RollW() // o. -> .o
    {
        //  ++x;
        int buff = d;
        d = r;
        r = u;
        u = l;
        l = buff;
    }


    vector< Dice > makeDice()
    {
        vector< Dice > ret;
        for(int i = 0; i < 6; i++) {
            Dice d(*this);
            if(i == 1) d.RollN();
            if(i == 2) d.RollS();
            if(i == 3) d.RollS(), d.RollS();
            if(i == 4) d.RollL();
            if(i == 5) d.RollR();
            for(int j = 0; j < 4; j++) {
                ret.emplace_back(d);
                d.RollE();
            }
        }
        return (ret);
    }
};

int h,w;
vector<string> s(100);
bool vis[100][100];

bool dfs(int y,int x,Dice dice){
    if(y == h - 1 && x == w - 1) return true;
    if(vis[y][x]) return false;
    vis[y][x] = true;
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if(0<=ny&&ny<h&&0<=nx&&nx<w){
            Dice ndice = dice;
            if(i == 0) ndice.RollW();
            if(i == 1) ndice.RollN();
            if(i == 2) ndice.RollE();
            if(i == 3) ndice.RollS();
            if(ndice.d == s[ny][nx] - '0' && dfs(ny, nx, ndice)) return true;
        }
    }
    return false;
}

int main(){
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    Dice dice;
    dice.d = 6;
    dice.u = 1;
    dice.r = 3;
    dice.l = 4;
    dice.f = 2;
    dice.b = 5;
    if(dfs(0,0,dice)) puts("YES");
    else puts("NO");
    return 0;
}

