#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct DICE {
    int L, R, U, D, B, F;
    void right() {
        int x;
        x = R;
        R = U;
        U = L;
        L = D;
        D = x;
    }
    void left() {
        int x;
        x = L;
        L = U;
        U = R;
        R = D;
        D = x;
    }
    void down() {
        int x;
        x = F;
        F = U;
        U = B;
        B = D;
        D = x;
    }
    void up() {
        int x;
        x = B;
        B = U;
        U = F;
        F = D;
        D = x;
    }
};
int main() {
    int h, w;
    cin >> h >> w;
    auto v = make_vec<int>(h, w);
    rep(i, h) rep(j, w) {
        char c;
        cin >> c;
        if (c == '#')
            v[i][j] = -1;
        else
            v[i][j] = c - '0';
    }

    auto d = make_vec<DICE>(h, w);
    auto dp = make_vec<int>(h, w);

    d[0][0] = {4, 3, 1, 6, 5, 2};
    dp[0][0] = 1;
    rep(_, 1000) {
        rep(i, h) {
            rep(j, w) {
                if (j + 1 < w && v[i][j + 1] != -1) {
                    d[i][j].right();
                    if (d[i][j].D == v[i][j + 1]) {
                        d[i][j + 1] = d[i][j];
                        dp[i][j + 1] |= dp[i][j];
                    }
                    d[i][j].left();
                }
                if (i + 1 < h && v[i + 1][j] != -1) {
                    d[i][j].down();
                    if (d[i][j].D == v[i + 1][j]) {
                        d[i + 1][j] = d[i][j];
                        dp[i + 1][j] |= dp[i][j];
                    }
                    d[i][j].up();
                }
                if (j - 1 >= 0 && v[i][j - 1] != -1 && dp[i][j] == 1 &&
                    dp[i][j - 1] == 0) {
                    d[i][j].left();
                    if (d[i][j].D == v[i][j - 1]) {
                        d[i][j - 1] = d[i][j];
                        dp[i][j - 1] |= dp[i][j];
                    }
                    d[i][j].right();
                }
                if (i - 1 >= 0 && v[i - 1][j] != -1 && dp[i][j] == 1 &&
                    dp[i - 1][j] == 0) {
                    d[i][j].up();
                    if (d[i][j].D == v[i - 1][j]) {
                        d[i - 1][j] = d[i][j];
                        dp[i - 1][j] |= dp[i][j];
                    }
                    d[i][j].down();
                }
            }
        }
    }
    /*
    cout << endl;
    rep(i, h) {
        rep(j, w) cout << d[i][j].D;
        cout << endl;
    }
    */
    cout << (dp[h - 1][w - 1] ? "YES" : "NO") << endl;
}



Measured memory_bytes: 3288