#include <bits/stdc++.h>
using namespace std;
struct Dice {
  int top, bottom;
  int s1, s2, s3, s4;
  Dice() {
    top = bottom = -1;
    s1 = s2 = s3 = s4 = -1;
  }
};
int main() {
  int n;
  cin >> n;
  int x;
  cin >> x;
  vector<Dice> dice;
  {
    Dice d;
    cin >> d.s1 >> d.s2;
    d.top = x;
    d.s3 = 7 - d.s1;
    d.s4 = 7 - d.s2;
    d.bottom = 7 - d.top;
    dice.push_back(d);
  }
  for (int i = 1; i < n; i++) {
    Dice d;
    cin >> d.s1 >> d.s2;
    d.s3 = 7 - d.s1;
    d.s4 = 7 - d.s2;
    dice.push_back(d);
  }
  for (int d = 1; d < dice.size(); d++) {
    vector<pair<int, int>> poss;
    for (int j = 1; j <= 6; j++) {
      if (dice[d].s1 == j || dice[d].s2 == j || dice[d].s3 == j ||
          dice[d].s4 == j) {
        continue;
      }
      if (dice[d - 1].top == j)
        continue;
      else {
        poss.push_back(make_pair(j, 7 - j));
      }
    }
    if (poss.size() > 1 || poss.size() == 0) {
      cout << "NO\n";
      return 0;
    } else {
      dice[d].top = poss[0].first;
      dice[d].bottom = 7 - poss[0].second;
    }
  }
  for (int i = 1; i < dice.size(); i++) {
    if (dice[i].top == -1 || dice[i].top == dice[i - 1].top) {
      cout << "NO\n";
      exit(1);
    }
  }
  cout << "YES\n";
}
