#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> ac;
  ac[12] = 34;
  ac[13] = 25;
  ac[14] = 25;
  ac[15] = 34;
  ac[23] = 16;
  ac[24] = 16;
  ac[26] = 34;
  ac[35] = 16;
  ac[36] = 25;
  ac[45] = 16;
  ac[46] = 25;
  ac[56] = 34;
  set<int> anw;
  int n, f;
  cin >> n >> f;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    anw.insert(ac[a * 10 + b]);
  }
  cout << (anw.size() == 1 ? "YES" : "NO") << endl;
}
