#include <bits/stdc++.h>
using namespace std;
void read_and_solve() {
  long long int n = ({
    long long int a;
    scanf("%lld", &a);
    a;
  });
  long long int x = ({
    long long int a;
    scanf("%lld", &a);
    a;
  });
  long long int a = ({
    long long int a;
    scanf("%lld", &a);
    a;
  }),
                b = ({
                  long long int a;
                  scanf("%lld", &a);
                  a;
                });
  long long int c = 7 - a, d = 7 - b;
  long long int ar1[10], ar2[10];
  ar1[0] = a;
  ar2[0] = b;
  ar1[1] = b;
  ar2[1] = c;
  ar1[2] = d;
  ar2[2] = a;
  ar1[3] = c;
  ar2[3] = d;
  ar1[4] = b;
  ar2[4] = a;
  ar1[5] = c;
  ar2[5] = b;
  ar1[6] = a;
  ar2[6] = d;
  ar1[7] = d;
  ar2[7] = c;
  bool f = true;
  for (long long int i = 2; i <= n; i++) {
    long long int y1 = ({
      long long int a;
      scanf("%lld", &a);
      a;
    }),
                  y2 = ({
                    long long int a;
                    scanf("%lld", &a);
                    a;
                  });
    long long int cnt = 0;
    for (long long int j = 0; j < 8; j++) {
      if (y1 == ar1[j] && y2 == ar2[j]) cnt = 1;
    }
    if (cnt == 0) f = false;
  }
  if (f == true)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  read_and_solve();
  return 0;
}
