#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
typedef pair<int, int> p;
vector< int64_t > divisor(int64_t n) {
	vector< int64_t > ret;
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
long long mod = 1e9 + 7;
p mov[4] = { p(0,1),p(1,0),p(-1,0),p(0,-1) };
int main(int argc, char* argv[]) {
	int h, w;
	cin >> h >> w;
	int grid[103][103];
	int visit[103][103];
	for (int i = 0; i < 103; i++) {
		for (int j = 0; j < 103; j++) {
			visit[i][j] = 0;
		}
	}
	for (int i = 1; i <= h; i++) {
		string str;
		cin >> str;
		for (int j = 1; j <= w; j++) {
			if (i % 2 == 0 && j % 2 == 0) {
				grid[i][j] = 0;
				continue;
			}
			int num;
			int s = i / 2;
			int t = j / 2;
			if (i % 2 == 1 && j % 2 == 1) {
				if ((s + t) % 2 == 0)num = 6;
				else num = 1;
			}
			if (i % 2 == 1 && j % 2 == 0) {
				if (t % 2 == 1)num = 3;
				else num = 4;
			}
			if (i % 2 == 0 && j % 2 == 1) {
				if (s % 2 == 1)num = 2;
				else num = 5;
			}
			if (str[j-1] - '0' == num)grid[i][j] = 1;
			else grid[i][j] = 0;
		}
	}
	queue<p>que;
	que.push(p(1, 1));
	visit[1][1] = 1;
	while (!que.empty()) {
		p now = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			p next = p(now.first + mov[i].first, now.second + mov[i].second);
			if (next.first <= h &&next.first>=1&& next.second <= w &&next.second>=1&& visit[next.first][next.second] == 0 && grid[next.first][next.second] == 1) {
				que.push(next);
				visit[next.first][next.second] = 1;
			}
		}
	}
	if (visit[h][w] == 1) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
}

