#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n, top;
int ar[7] = {0, 6, 5, 4, 3, 2, 1};
int main() {
  cin >> n >> top;
  int last = top;
  for (int i = 0; i < n; ++i) {
    last = ar[last];
    int a, b;
    cin >> a >> b;
    if (a == last || ar[a] == last || b == last || ar[b] == last) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
