#include <bits/stdc++.h>
int main() {
  int n, x, l, r;
  scanf("%d", &n);
  scanf("%d", &x);
  if (n == 1) {
    printf("YES\n");
    return 0;
  }
  scanf("%d%d", &l, &r);
  int l1, r1;
  x = 7 - x;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &l, &r);
    l1 = 7 - l;
    r1 = 7 - r;
    int tmp[2];
    int tn = 0;
    for (int i = 1; i <= 6; i++) {
      if (i != l && i != r && i != l1 && i != r1) tmp[tn++] = i;
    }
    int nx = -1;
    if (tmp[0] == x) nx = tmp[1];
    if (tmp[1] == x) nx = tmp[0];
    if (nx == -1) {
      printf("NO\n");
      return 0;
    }
    x = nx;
  }
  printf("YES\n");
  return 0;
}
