#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;
typedef pair<llint, llint> P;

llint h, w;
char c[105][105];
bool used[105][105];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void bfs()
{
	queue<P> Q;
	Q.push(P(0, 0));
	used[0][0] = true;
	
	int x, y;
	while(Q.size()){
		x = Q.front().first, y = Q.front().second;
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if(c[nx][ny] == '#') continue;
			if(used[nx][ny]) continue;
			Q.push(P(nx, ny));
			used[nx][ny] = true;
		}
	}
}


int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w;
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			cin >> c[x][y];
		}
	}
	
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			if(x%4 == 1){
				if(c[x][y] != '3') c[x][y] = '#';
			}
			if(x%4 == 3){
				if(c[x][y] != '4') c[x][y] = '#';
			}
			if(y%4 == 1){
				if(c[x][y] != '2') c[x][y] = '#';
			}
			if(y%4 == 3){
				if(c[x][y] != '5') c[x][y] = '#';
			}
			if(x%2 == 0 && y%2 == 0){
				if((x/2+y/2)%2){
					if(c[x][y] != '1') c[x][y] = '#';
				}
				else{
					if(c[x][y] != '6') c[x][y] = '#';
				}
			}
		}
	}
	
	bfs();
	
	if(used[w-1][h-1]) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}
