#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll MOD = 998244353;
int h, w;
vector<string> sq;
bool ans = false;

// state[0] = 上
// state[1] = 手前
// state[2] = 右
// state[3] = 左
// state[4] = 奥
// state[5] = 下

int used[101][101];

void dfs(vector<char> state, int x, int y) {
  if (used[x][y] == 1) { return; }
  used[x][y] = 1;
  if (x == h - 1 && y == w - 1) {
    ans = true;
    return;
  }
  if (y - 1 >= 0) {
    if (sq[x][y - 1] == state[3]) {
      dfs({state[2], state[1], state[5], state[0], state[4], state[3]}, x,
          y - 1);
    }
  }
  if (x - 1 >= 0) {
    if (sq[x - 1][y] == state[4]) {
      dfs({state[1], state[5], state[2], state[3], state[0], state[4]}, x - 1,
          y);
    }
  }
  if (y + 1 < w) {
    if (sq[x][y + 1] == state[2]) {
      dfs({state[3], state[1], state[0], state[5], state[4], state[2]}, x,
          y + 1);
    }
  }
  if (x + 1 < h) {
    if (sq[x + 1][y] == state[1]) {
      dfs({state[4], state[0], state[2], state[3], state[5], state[1]}, x + 1,
          y);
    }
  }
}

signed main() {

  cin >> h >> w;
  sq.resize(h);
  vector<char> state(6);
  for (int i = 0; i < 6; i += 1) {
    state[i] = char(int('1') + i);
  }
  for (int i = 0; i < h; i += 1) {
    cin >> sq[i];
  }
  dfs(state, 0, 0);
  if (ans) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
