#include<iostream>
#include<tuple>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

typedef tuple<int, int, vector<int>> T3;//座標、

int H, W;
char field[100 + 10][100 + 10];
bool visited[100 + 10][100 + 10];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cin >> field[i][j];
	}
	
	queue<T3> Q;
	vector<int> state = {1, 2, 3, 5, 4, 6};
	Q.push(make_tuple(0, 0, state));
	while (Q.size()) {
		auto now = Q.front();
		int x = get<0>(now), y = get<1>(now);
		auto ns = get<2>(now);
		Q.pop();
		if (x == H - 1 && y == W - 1) {
			cout << "YES" << endl;
			return 0;
		}

		//上向き
		if (x > 0 && field[x - 1][y] != '#' && !visited[x - 1][y]) {
			vector<int> newstate(6);
			newstate[0] = ns[1], newstate[1] = ns[5], newstate[2] = ns[2];
			newstate[3] = ns[0], newstate[4] = ns[4], newstate[5] = ns[3];
			if (newstate[5] == field[x - 1][y] - '0') {
				visited[x - 1][y] = true;
				Q.push(make_tuple(x - 1, y, newstate));
			}
		}
		
		//下向き
		if (x < H - 1 && field[x + 1][y] != '#' && !visited[x + 1][y]) {
			vector<int> newstate(6);
			newstate[0] = ns[3], newstate[1] = ns[0], newstate[2] = ns[2];
			newstate[3] = ns[5], newstate[4] = ns[4], newstate[5] = ns[1];
			if (newstate[5] == field[x + 1][y] - '0') {
				visited[x + 1][y] = true;
				Q.push(make_tuple(x + 1, y, newstate));
			}
		}
		
		//左向き
		if (y > 0 && field[x][y - 1] != '#' && !visited[x][y - 1]) {
			vector<int> newstate(6);
			newstate[0] = ns[2], newstate[1] = ns[1], newstate[2] = ns[5];
			newstate[3] = ns[3], newstate[4] = ns[0], newstate[5] = ns[4];
			if (newstate[5] == field[x][y - 1] - '0') {
				visited[x][y - 1] = true;
				Q.push(make_tuple(x, y - 1, newstate));
			}
		}
		
		//右向き
		if (y < W - 1 && field[x][y + 1] != '#' && !visited[x][y + 1]) {
			vector<int> newstate(6);
			newstate[0] = ns[4], newstate[1] = ns[1], newstate[2] = ns[0];
			newstate[3] = ns[3], newstate[4] = ns[5], newstate[5] = ns[2];
			if (newstate[5] == field[x][y + 1] - '0') {
				visited[x][y + 1] = true;
				Q.push(make_tuple(x, y + 1, newstate));
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
