#include <bits/stdc++.h>
using namespace std;
string sortString(string& str) {
  sort(str.begin(), str.end());
  return str;
}
string operator*(const string& s, unsigned int n) {
  stringstream out;
  while (n--) out << s;
  return out.str();
}
int knapSack(int value[], int weight[], int w, int n) {
  if (w == 0 || n == 0) {
    return 0;
  }
  if (weight[n - 1] <= w) {
    return max(value[n - 1] + knapSack(value, weight, w - weight[n - 1], n - 1),
               knapSack(value, weight, w, n - 1));
  } else if (weight[n - 1] > w)
    return knapSack(value, weight, w, n - 1);
}
int ribbon(int n, int a, int b, int c) {
  int d = min(min(a, b), c);
  if (n == d) return 0;
}
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = 2; i < n + 1; i++) {
    if (prime[i] == true) {
      cout << i << endl;
    }
  }
}
bool length_con(int n, int m, int k) {
  int d = 0;
  int sum = 0;
  while (n > 0) {
    int c = n % 10;
    sum += c;
    d++;
    n = n / 10;
  }
  if (sum == m && d == k) {
    return true;
  } else {
    return false;
  }
}
int min_arr(int arr[], int n) {
  int minim = 31;
  for (int i = 0; i < n; i++) {
    if (arr[i] < minim) {
      minim = i;
    }
  }
  return minim;
}
int max_arr(int arr[], int n) {
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > maxi) {
      maxi = i;
    }
  }
  return maxi;
}
int sum(int arr[], int n) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
  }
  return sum;
}
void sortEst() {
  int c, t;
  cin >> c >> t;
  double lo = 1;
  double hi = 2000000000;
  while (hi - lo > 0) {
    double mid = (lo + hi) / 2;
    double time = c * mid * log2(mid);
    if (t == time) {
      cout << mid << endl;
      break;
    } else if (t > time) {
      lo = mid;
    } else if (t < time) {
      hi = mid;
    }
  }
}
int ans[1000];
int tiles(int n) {
  ans[1] = 1;
  ans[2] = 2;
  for (int i = 3; i <= n; i++) {
    ans[i] = ans[i - 1] + ans[i - 2];
  }
  return ans[n];
}
int supw(int n, int arr[], int m) {
  if (m == n - 1) return arr[m];
  if (m == n - 2) return arr[m];
  if (m == n - 3) return arr[m];
  return min(arr[m] + supw(n, arr, m + 1),
             min(arr[m] + supw(n, arr, m + 2), arr[m] + supw(n, arr, m + 3)));
}
bool isSubsetSum(int set[], int n, int sum) {
  bool subset[n + 1][sum + 1];
  for (int i = 0; i <= n; i++) subset[i][0] = true;
  for (int i = 1; i <= sum; i++) subset[0][i] = false;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      if (j < set[i - 1]) subset[i][j] = subset[i - 1][j];
      if (j >= set[i - 1])
        subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]];
    }
  }
  return subset[n][sum];
}
bool equal_sum_partition(int arr[], int n, int sum) {
  if (n == 0 and sum != 0) return false;
  if (sum == 0) return true;
  if (arr[n - 1] > sum) return equal_sum_partition(arr, n - 1, sum);
  return equal_sum_partition(arr, n - 1, sum) ||
         equal_sum_partition(arr, n - 1, sum - arr[n - 1]);
}
int subset_count(int arr[], int n, int sum) {
  int subset[n + 1][sum + 1];
  memset(subset, 0, sizeof(subset));
  for (int i = 0; i <= n; i++) subset[i][0] = 1;
  for (int i = 1; i <= sum; i++) subset[0][i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      if (j < arr[i - 1])
        subset[i][j] = subset[i - 1][j];
      else {
        subset[i][j] = subset[i - 1][j] + subset[i - 1][j - arr[i - 1]];
      }
    }
  }
  return subset[n][sum];
}
int find_min(int arr[], int n) {
  int diff = 100;
  int range = accumulate(arr, arr + n, 0);
  for (int i = 0; i <= range / 2; i++) {
    if (isSubsetSum(arr, n, i)) {
      diff = min(diff, range - 2 * i);
    }
  }
  return diff;
}
int unbounded_knapsack(int w, int value[], int weight[], int m) {
  if (m == 0 || w == 0) return 0;
  if (weight[m - 1] > w)
    return unbounded_knapsack(w, value, weight, m - 1);
  else
    return max(
        value[m - 1] + unbounded_knapsack(w - value[m - 1], value, weight, m),
        unbounded_knapsack(w, value, weight, m - 1));
}
int rod_cutting(int arr[], int n) {
  int dp[n + 1][n + 1];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (i > j)
        dp[i][j] = dp[i - 1][j];
      else
        dp[i][j] = max(dp[i - 1][j], arr[i - 1] + dp[i][j - i]);
    }
  }
  return dp[n][n];
}
int coin_change_no_of_ways(int arr[], int n, int sum) {
  if (sum == 0) return 1;
  if (n <= 0 && sum > 0) return 0;
  if (arr[n - 1] > sum) return coin_change_no_of_ways(arr, n - 1, sum);
  return coin_change_no_of_ways(arr, n - 1, sum) +
         coin_change_no_of_ways(arr, n, sum - arr[n - 1]);
}
int maxSum(int arr[], int n, int k) {
  int res = 0;
  for (int i = 0; i < k; i++) res += arr[i];
  int idx = 0;
  int curr_sum = res;
  for (int i = k; i < n; i++) {
    curr_sum += arr[i] - arr[i - k];
    if (curr_sum < res) {
      idx = i;
    }
    res = min(res, curr_sum);
  }
  if (idx == 0) return 2;
  return idx;
}
int fact(int n) {
  if (n == 0 || n == 1) return 1;
  return n * fact(n - 1);
}
int pair_cal(int n) {
  if (n == 1) return 0;
  return (n - 1) + pair_cal(n - 1);
}
int most_repeating(int arr[], int n) {
  unordered_map<int, int> v;
  for (int i = 0; i < n; i++) {
    v[arr[i]] += 1;
  }
  int freq = -1;
  int res = 0;
  for (auto i : v) {
    if (i.second > freq) {
      freq = i.second;
      res = i.first;
    }
  }
  return res;
}
int get_smallest_divisor(int n) {
  if (n % 2 == 0)
    return 2;
  else {
    for (int i = 3; i * i <= n; i += 2) {
      if (n % i == 0) return i;
    }
  }
  return n;
}
void show_pq(priority_queue<int> pq) {
  priority_queue<int> g = pq;
  while (!g.empty()) {
    cout << g.top() << " ";
    g.pop();
  }
  cout << endl;
}
void pairsort(int a[], int b[], int n) {
  pair<int, int> pairt[n];
  for (int i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (int i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
void bin(unsigned n) {
  unsigned i;
  for (i = 1 << 31; i > 0; i = i / 2) (n & i) ? printf("1") : printf("0");
}
vector<pair<int, int>> find_sub_sum_0(int arr[], int n) {
  unordered_map<int, vector<int>> mp;
  vector<pair<int, int>> out;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
    if (sum == 0) {
      out.push_back(make_pair(0, i));
    }
    if (mp.find(sum) != mp.end()) {
      vector<int> vc = mp[sum];
      for (auto it = vc.begin(); it != vc.end(); it++) {
      }
    }
  }
  return out;
}
int cnt[1000001];
int solve(int arr[], int n, int k, int z) {
  int dp[n + 1];
  dp[0] = 0, dp[1] = arr[0];
  for (int i = 2; i < n + 1; i++) {
    if (k == 0) {
      dp[i] = dp[i - 1];
      continue;
    }
    if (z == 0) {
      if (k > 0) {
        dp[i] = dp[i - 1] + arr[i - 1];
        k--;
      } else {
        dp[i] = dp[i - 1];
      }
    } else {
      dp[i] = max(dp[i - 1] + arr[i - 2], dp[i - 1] + arr[i - 1]);
      if (dp[i] == dp[i - 1] + arr[i - 2]) {
        z--;
      }
      k--;
    }
  }
  for (int i = 0; i < n + 1; i++) {
    cout << dp[i] << " ";
  }
  cout << endl;
  return dp[n];
}
bool cmp(pair<string, int>& a, pair<string, int>& b) {
  return a.second < b.second;
}
bool is_prime(int n) {
  if (n == 1) {
    return false;
  }
  int i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      return false;
    }
    i += 1;
  }
  return true;
}
int solve(long long arr[], long long n, long long sum) {
  vector<long long> a;
  if (sum % n) {
    sum -= n;
    long long cnter = 1;
    a.push_back(n);
    arr[n - 1] = -1;
    for (long long i = 1; sum > 0; i++) {
      sum -= i;
      a.push_back(i);
      arr[i - 1] = -1;
      if (sum == 0) break;
      sum -= n - i;
      a.push_back(n - i);
      arr[n - i - 1] = -1;
    }
    cout << a.size() << endl;
    for (auto i : a) cout << i << " ";
    cout << endl;
    cout << n - a.size() << endl;
    for (long long i = 0; i < n; i++) {
      if (arr[i] != -1) cout << arr[i] << " ";
    }
    cout << endl;
  } else {
    sum -= n;
    long long cnter = 1;
    a.push_back(n);
    arr[n - 1] = -1;
    for (long long i = 1; sum != 0; i++) {
      sum -= i;
      a.push_back(i);
      arr[i - 1] = -1;
      if (sum == 0) break;
      sum -= n - i;
      a.push_back(n - i);
      arr[n - i - 1] = -1;
    }
    cout << a.size() << endl;
    for (auto i : a) cout << i << " ";
    cout << endl;
    cout << n - a.size() << endl;
    for (long long i = 0; i < n; i++) {
      if (arr[i] != -1) cout << arr[i] << " ";
    }
    cout << endl;
  }
}
set<string> str;
void permute(string s, int l, int r) {
  if (l == r) {
    str.insert(s);
  } else {
    for (int i = l; i <= r; i++) {
      swap(s[i], s[l]);
      permute(s, l + 1, r);
      swap(s[i], s[l]);
    }
  }
}
int main() {
  int n, x, a, c, d, e, f;
  cin >> n;
  cin >> x;
  a = 7 - x;
  int flag = 0;
  while (n--) {
    int arr[6] = {1, 2, 3, 4, 5, 6};
    cin >> c >> d;
    e = 7 - c;
    f = 7 - d;
    arr[c - 1] = 0, arr[d - 1] = 0, arr[e - 1] = 0, arr[f - 1] = 0,
            arr[a - 1] = 0;
    if (c == a || d == a || e == a || f == a) {
      flag = 1;
    } else {
      for (int i = 0; i < 6; i++) {
        if (arr[i] != 0) {
          a = arr[i];
          break;
        }
      }
    }
  }
  if (flag)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

### Prompt

Construct a CPP code solution to the problem outlined:

A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).

<image>

Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).

Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower.

The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numbers Bob sees on the two sidelong faces of the i-th dice in the tower.

Consider the dice in the tower indexed from top to bottom from 1 to n. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.

Output

Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).

Examples

Input

3
6
3 2
5 4
2 4


Output

YES

Input

3
3
2 6
4 1
5 3


Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string sortString(string& str) {
  sort(str.begin(), str.end());
  return str;
}
string operator*(const string& s, unsigned int n) {
  stringstream out;
  while (n--) out << s;
  return out.str();
}
int knapSack(int value[], int weight[], int w, int n) {
  if (w == 0 || n == 0) {
    return 0;
  }
  if (weight[n - 1] <= w) {
    return max(value[n - 1] + knapSack(value, weight, w - weight[n - 1], n - 1),
               knapSack(value, weight, w, n - 1));
  } else if (weight[n - 1] > w)
    return knapSack(value, weight, w, n - 1);
}
int ribbon(int n, int a, int b, int c) {
  int d = min(min(a, b), c);
  if (n == d) return 0;
}
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = 2; i < n + 1; i++) {
    if (prime[i] == true) {
      cout << i << endl;
    }
  }
}
bool length_con(int n, int m, int k) {
  int d = 0;
  int sum = 0;
  while (n > 0) {
    int c = n % 10;
    sum += c;
    d++;
    n = n / 10;
  }
  if (sum == m && d == k) {
    return true;
  } else {
    return false;
  }
}
int min_arr(int arr[], int n) {
  int minim = 31;
  for (int i = 0; i < n; i++) {
    if (arr[i] < minim) {
      minim = i;
    }
  }
  return minim;
}
int max_arr(int arr[], int n) {
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > maxi) {
      maxi = i;
    }
  }
  return maxi;
}
int sum(int arr[], int n) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
  }
  return sum;
}
void sortEst() {
  int c, t;
  cin >> c >> t;
  double lo = 1;
  double hi = 2000000000;
  while (hi - lo > 0) {
    double mid = (lo + hi) / 2;
    double time = c * mid * log2(mid);
    if (t == time) {
      cout << mid << endl;
      break;
    } else if (t > time) {
      lo = mid;
    } else if (t < time) {
      hi = mid;
    }
  }
}
int ans[1000];
int tiles(int n) {
  ans[1] = 1;
  ans[2] = 2;
  for (int i = 3; i <= n; i++) {
    ans[i] = ans[i - 1] + ans[i - 2];
  }
  return ans[n];
}
int supw(int n, int arr[], int m) {
  if (m == n - 1) return arr[m];
  if (m == n - 2) return arr[m];
  if (m == n - 3) return arr[m];
  return min(arr[m] + supw(n, arr, m + 1),
             min(arr[m] + supw(n, arr, m + 2), arr[m] + supw(n, arr, m + 3)));
}
bool isSubsetSum(int set[], int n, int sum) {
  bool subset[n + 1][sum + 1];
  for (int i = 0; i <= n; i++) subset[i][0] = true;
  for (int i = 1; i <= sum; i++) subset[0][i] = false;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      if (j < set[i - 1]) subset[i][j] = subset[i - 1][j];
      if (j >= set[i - 1])
        subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]];
    }
  }
  return subset[n][sum];
}
bool equal_sum_partition(int arr[], int n, int sum) {
  if (n == 0 and sum != 0) return false;
  if (sum == 0) return true;
  if (arr[n - 1] > sum) return equal_sum_partition(arr, n - 1, sum);
  return equal_sum_partition(arr, n - 1, sum) ||
         equal_sum_partition(arr, n - 1, sum - arr[n - 1]);
}
int subset_count(int arr[], int n, int sum) {
  int subset[n + 1][sum + 1];
  memset(subset, 0, sizeof(subset));
  for (int i = 0; i <= n; i++) subset[i][0] = 1;
  for (int i = 1; i <= sum; i++) subset[0][i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      if (j < arr[i - 1])
        subset[i][j] = subset[i - 1][j];
      else {
        subset[i][j] = subset[i - 1][j] + subset[i - 1][j - arr[i - 1]];
      }
    }
  }
  return subset[n][sum];
}
int find_min(int arr[], int n) {
  int diff = 100;
  int range = accumulate(arr, arr + n, 0);
  for (int i = 0; i <= range / 2; i++) {
    if (isSubsetSum(arr, n, i)) {
      diff = min(diff, range - 2 * i);
    }
  }
  return diff;
}
int unbounded_knapsack(int w, int value[], int weight[], int m) {
  if (m == 0 || w == 0) return 0;
  if (weight[m - 1] > w)
    return unbounded_knapsack(w, value, weight, m - 1);
  else
    return max(
        value[m - 1] + unbounded_knapsack(w - value[m - 1], value, weight, m),
        unbounded_knapsack(w, value, weight, m - 1));
}
int rod_cutting(int arr[], int n) {
  int dp[n + 1][n + 1];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (i > j)
        dp[i][j] = dp[i - 1][j];
      else
        dp[i][j] = max(dp[i - 1][j], arr[i - 1] + dp[i][j - i]);
    }
  }
  return dp[n][n];
}
int coin_change_no_of_ways(int arr[], int n, int sum) {
  if (sum == 0) return 1;
  if (n <= 0 && sum > 0) return 0;
  if (arr[n - 1] > sum) return coin_change_no_of_ways(arr, n - 1, sum);
  return coin_change_no_of_ways(arr, n - 1, sum) +
         coin_change_no_of_ways(arr, n, sum - arr[n - 1]);
}
int maxSum(int arr[], int n, int k) {
  int res = 0;
  for (int i = 0; i < k; i++) res += arr[i];
  int idx = 0;
  int curr_sum = res;
  for (int i = k; i < n; i++) {
    curr_sum += arr[i] - arr[i - k];
    if (curr_sum < res) {
      idx = i;
    }
    res = min(res, curr_sum);
  }
  if (idx == 0) return 2;
  return idx;
}
int fact(int n) {
  if (n == 0 || n == 1) return 1;
  return n * fact(n - 1);
}
int pair_cal(int n) {
  if (n == 1) return 0;
  return (n - 1) + pair_cal(n - 1);
}
int most_repeating(int arr[], int n) {
  unordered_map<int, int> v;
  for (int i = 0; i < n; i++) {
    v[arr[i]] += 1;
  }
  int freq = -1;
  int res = 0;
  for (auto i : v) {
    if (i.second > freq) {
      freq = i.second;
      res = i.first;
    }
  }
  return res;
}
int get_smallest_divisor(int n) {
  if (n % 2 == 0)
    return 2;
  else {
    for (int i = 3; i * i <= n; i += 2) {
      if (n % i == 0) return i;
    }
  }
  return n;
}
void show_pq(priority_queue<int> pq) {
  priority_queue<int> g = pq;
  while (!g.empty()) {
    cout << g.top() << " ";
    g.pop();
  }
  cout << endl;
}
void pairsort(int a[], int b[], int n) {
  pair<int, int> pairt[n];
  for (int i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (int i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
void bin(unsigned n) {
  unsigned i;
  for (i = 1 << 31; i > 0; i = i / 2) (n & i) ? printf("1") : printf("0");
}
vector<pair<int, int>> find_sub_sum_0(int arr[], int n) {
  unordered_map<int, vector<int>> mp;
  vector<pair<int, int>> out;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
    if (sum == 0) {
      out.push_back(make_pair(0, i));
    }
    if (mp.find(sum) != mp.end()) {
      vector<int> vc = mp[sum];
      for (auto it = vc.begin(); it != vc.end(); it++) {
      }
    }
  }
  return out;
}
int cnt[1000001];
int solve(int arr[], int n, int k, int z) {
  int dp[n + 1];
  dp[0] = 0, dp[1] = arr[0];
  for (int i = 2; i < n + 1; i++) {
    if (k == 0) {
      dp[i] = dp[i - 1];
      continue;
    }
    if (z == 0) {
      if (k > 0) {
        dp[i] = dp[i - 1] + arr[i - 1];
        k--;
      } else {
        dp[i] = dp[i - 1];
      }
    } else {
      dp[i] = max(dp[i - 1] + arr[i - 2], dp[i - 1] + arr[i - 1]);
      if (dp[i] == dp[i - 1] + arr[i - 2]) {
        z--;
      }
      k--;
    }
  }
  for (int i = 0; i < n + 1; i++) {
    cout << dp[i] << " ";
  }
  cout << endl;
  return dp[n];
}
bool cmp(pair<string, int>& a, pair<string, int>& b) {
  return a.second < b.second;
}
bool is_prime(int n) {
  if (n == 1) {
    return false;
  }
  int i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      return false;
    }
    i += 1;
  }
  return true;
}
int solve(long long arr[], long long n, long long sum) {
  vector<long long> a;
  if (sum % n) {
    sum -= n;
    long long cnter = 1;
    a.push_back(n);
    arr[n - 1] = -1;
    for (long long i = 1; sum > 0; i++) {
      sum -= i;
      a.push_back(i);
      arr[i - 1] = -1;
      if (sum == 0) break;
      sum -= n - i;
      a.push_back(n - i);
      arr[n - i - 1] = -1;
    }
    cout << a.size() << endl;
    for (auto i : a) cout << i << " ";
    cout << endl;
    cout << n - a.size() << endl;
    for (long long i = 0; i < n; i++) {
      if (arr[i] != -1) cout << arr[i] << " ";
    }
    cout << endl;
  } else {
    sum -= n;
    long long cnter = 1;
    a.push_back(n);
    arr[n - 1] = -1;
    for (long long i = 1; sum != 0; i++) {
      sum -= i;
      a.push_back(i);
      arr[i - 1] = -1;
      if (sum == 0) break;
      sum -= n - i;
      a.push_back(n - i);
      arr[n - i - 1] = -1;
    }
    cout << a.size() << endl;
    for (auto i : a) cout << i << " ";
    cout << endl;
    cout << n - a.size() << endl;
    for (long long i = 0; i < n; i++) {
      if (arr[i] != -1) cout << arr[i] << " ";
    }
    cout << endl;
  }
}
set<string> str;
void permute(string s, int l, int r) {
  if (l == r) {
    str.insert(s);
  } else {
    for (int i = l; i <= r; i++) {
      swap(s[i], s[l]);
      permute(s, l + 1, r);
      swap(s[i], s[l]);
    }
  }
}
int main() {
  int n, x, a, c, d, e, f;
  cin >> n;
  cin >> x;
  a = 7 - x;
  int flag = 0;
  while (n--) {
    int arr[6] = {1, 2, 3, 4, 5, 6};
    cin >> c >> d;
    e = 7 - c;
    f = 7 - d;
    arr[c - 1] = 0, arr[d - 1] = 0, arr[e - 1] = 0, arr[f - 1] = 0,
            arr[a - 1] = 0;
    if (c == a || d == a || e == a || f == a) {
      flag = 1;
    } else {
      for (int i = 0; i < 6; i++) {
        if (arr[i] != 0) {
          a = arr[i];
          break;
        }
      }
    }
  }
  if (flag)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

```