#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int h, w;
struct indata
{
    vector<int> masme;
    int inh, inw;
};
vector<int> dx;
vector<int> dy;

int main() {
    cin >> h >> w;
    vector< vector < int > > s(h, vector<int>(w, 0));
    vector< vector < bool > > sb(h, vector<bool>(w, false));
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            char ins;
            cin >> ins;
            if(ins == '#') {
                s.at(i).at(j) = -1;
            }else {
                s.at(i).at(j) = ins - '0';
            }
        }
    }

    dx.push_back(0);
    dx.push_back(1);
    dx.push_back(0);
    dx.push_back(-1);
    dy.push_back(-1);
    dy.push_back(0);
    dy.push_back(1);
    dy.push_back(0);

    indata first;
    first.masme.push_back(5);
    first.masme.push_back(3);
    first.inh = 0;
    first.inw = 0;
    queue<indata> que;
    que.push(first);
    sb.at(first.inh).at(first.inw) = true;

    bool flg = false;
    int ue = 0;
    int migi = 0;
    int sita = 0;
    int hidari = 0;
    while(!que.empty()) {
        indata exe = que.front();
        que.pop();
        if(exe.inh == h-1 && exe.inw == w-1) {
            flg = true;
            break;
        }else {
            int under = s.at(exe.inh).at(exe.inw);
            for(int i = 0; i < 4; ++i) {
                int nex = exe.inw + dx.at(i);
                int ney = exe.inh + dy.at(i);
                if(nex >= 0 && nex < w && ney >= 0 && ney < h && s.at(ney).at(nex) != -1 && (!sb.at(ney).at(nex))) {
                    ue = exe.masme.at(0); migi = exe.masme.at(1);
                    sita = 7-ue; hidari = 7-migi;
                    vector<int> check;
                    check.push_back(ue);
                    check.push_back(migi);
                    check.push_back(sita);
                    check.push_back(hidari);
                    if(s.at(ney).at(nex) == check.at(i)) {
                        indata next;
                        next.inh = ney;
                        next.inw = nex;
                        sb.at(ney).at(nex) = true;
                        if(i == 0) {
                            next.masme.push_back(7-under);
                            next.masme.push_back(check.at(1));
                        }else if(i == 1) {
                            next.masme.push_back(check.at(0));
                            next.masme.push_back(7-under);
                        }else if(i == 2) {
                            next.masme.push_back(under);
                            next.masme.push_back(check.at(1));
                        }else {
                            next.masme.push_back(check.at(0));
                            next.masme.push_back(under);
                        }
                        que.push(next);
                    }
                }
            }
        }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}
