#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
int p[1000005];
int ops;
int fin;
set<pair<int, int> >::iterator it;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= 1000002; i++) s.insert(make_pair(0, i));
  s.erase(make_pair(0, m));
  while (n--) {
    int k;
    scanf("%d", &k);
    if (k == m) {
      ops++;
      if (s.empty()) {
        cout << -1;
        return 0;
      }
      it = lower_bound(s.begin(), s.end(), make_pair(ops, 0));
      if (it == s.end()) {
        cout << -1;
        return 0;
      }
      if (it == s.begin()) continue;
      s.erase(s.begin(), (it));
    }
    if (k != m) {
      it = s.find(make_pair(p[k], k));
      if (it == s.end()) continue;
      p[k]++;
      s.erase(it);
      s.insert(make_pair(p[k], k));
    }
  }
  if (s.empty()) {
    cout << -1;
  } else {
    cout << (*s.begin()).second;
  }
  return 0;
}
