#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int top;
  cin >> top;
  int bottom;
  if (top == 1) {
    bottom = 6;
  } else if (top == 6) {
    bottom = 1;
  } else if (top == 2) {
    bottom = 5;
  } else if (top == 5) {
    bottom = 2;
  } else if (top == 3) {
    bottom = 4;
  } else if (top == 4) {
    bottom = 3;
  }
  for (int i = 0; i < (int)(n); ++i) {
    int a, b;
    cin >> a >> b;
    if (a != top && b != top && a != bottom && b != bottom) {
      continue;
    } else {
      cout << "NO"
           << "\n";
      return 0;
    }
  }
  cout << "YES" << '\n';
}
