#include <bits/stdc++.h>
using namespace std;
const int INFI = (1LL << 31) - 10;
const long long INFL = 1LL << 62;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
int main() {
  int n, x, a, b;
  cin >> n >> x;
  x = 7 - x;
  cin >> a >> b;
  for (int i = 2; i <= n; i++) {
    cin >> a >> b;
    int c1, c2;
    if (a == 5 || a == 2) {
      switch (b) {
        case 1:
        case 6:
          c1 = 3, c2 = 4;
          break;
        case 3:
        case 4:
          c1 = 1, c2 = 6;
          break;
      }
    } else if (a == 1 || a == 6) {
      switch (b) {
        case 2:
        case 5:
          c1 = 3, c2 = 4;
          break;
        case 3:
        case 4:
          c1 = 2, c2 = 5;
          break;
      }
    } else if (a == 3 || a == 4) {
      switch (b) {
        case 1:
        case 6:
          c1 = 2, c2 = 5;
          break;
        case 2:
        case 5:
          c1 = 1, c2 = 6;
          break;
      }
    }
    if (c1 != x && c2 != x) {
      cout << "NO";
      return 0;
    }
    if (c1 == x)
      x = c2;
    else
      x = c1;
  }
  cout << "YES";
  return 0;
}
