#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ad1, ad2, pos, flag = 0;
  cin >> n;
  int upface;
  cin >> upface;
  int notupface = 7 - upface;
  cin >> ad1 >> ad2;
  for (int i = 1; i < n; i++) {
    int a[7] = {0};
    int count = 0;
    a[0] = 1;
    cin >> ad1 >> ad2;
    a[ad1] = a[ad2] = a[7 - ad1] = a[7 - ad2] = 1;
    a[notupface] = 1;
    for (int i = 1; i <= 6; i++) {
      if (a[i] != 1) {
        pos = i;
        count++;
      }
    }
    if (count == 1) {
      notupface = 7 - pos;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "NO";
  else
    cout << "YES";
}
