#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const int MAXN = 400000;
const int MOD = 1000000000 + 7;
int N;
int A[MAXN], B[MAXN];
int reverse[7] = {-1, 6, 5, 4, 3, 2, 1};
void input() {
  scanf("%d", &N);
  scanf("%d", &A[0]);
  for (int i = 1; i <= N; i++) scanf("%d %d", &A[i], &B[i]);
}
int mex(vector<int> &A) {
  bool B[8] = {};
  for (int i = 0; i < A.size(); i++) B[A[i]] = 1;
  int mex = 1;
  while (B[mex]) mex++;
  return mex;
}
void solve() {
  int downCube = 7 - A[0];
  int upCube = A[0];
  for (int i = 1; i <= N; i++) {
    vector<int> C;
    C.push_back(A[i]);
    C.push_back(B[i]);
    C.push_back(7 - A[i]);
    C.push_back(7 - B[i]);
    int m = mex(C);
    if (m != downCube && m != upCube) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
int main() {
  input();
  solve();
  return 0;
}
