#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long H, W;
    cin >> H >> W;
    vector<vector<char>> kanou{{'6', '3', '1', '4'}, {'2', '0', '2', '0'}, {'1', '3', '6', '4'}, {'5', '0', '5', '0'}};
    vector<vector<unsigned long>> moveable(H + 2, vector<unsigned long>(W + 2));
    for(unsigned long i{0}; i < H; ++i){
        string S;
        cin >> S;
        for(unsigned long j{0}; j < W; ++j)moveable[i + 1][j + 1] = static_cast<unsigned long>(S[j] == kanou[i & 3][j & 3]);
    }
    vector<pair<unsigned long, unsigned long>> tansaku, dist{{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
    tansaku.emplace_back(1, 1);
    while(!tansaku.empty()){
        auto t = tansaku.back();
        tansaku.pop_back();
        moveable[t.first][t.second] = 0;
        if(t.first == H && t.second == W)return 0 & puts("YES");
        for(const auto& d : dist)if(moveable[t.first + d.first][t.second + d.second]){
            tansaku.emplace_back(t.first + d.first, t.second + d.second);
            moveable[t.first + d.first][t.second + d.second] = 0;
        }
    }
    return 0 & puts("NO");
}
