#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
int x, a, b, n;
bool num[8];
int main() {
  cin >> n;
  cin >> x;
  cin >> a >> b;
  bool ans = true;
  x = 7 - x;
  for (int i = (0); i < (n - 1); i++) {
    cin >> a >> b;
    memset(num, false, sizeof(num));
    num[a] = num[7 - a] = num[b] = num[7 - b] = true;
    int t = -1;
    for (int i = 1; i <= 6; i++)
      if (i != x && !num[i]) {
        if (t != -1) ans = false;
        t = i;
      }
    if (t == -1) ans = false;
    x = 7 - t;
  }
  if (ans)
    puts("YES");
  else
    puts("NO");
  return 0;
}
