#include <bits/stdc++.h>
using namespace std;
void doRoutine() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
ifstream fin("/home/max/user/alg/codeforces_clion/input.txt");
ofstream fout("/home/max/user/alg/codeforces_clion/output.txt");
const int64_t MAX_COLOR = 1000000;
signed main() {
  doRoutine();
  int64_t n, a;
  cin >> n >> a;
  vector<int64_t> c(n);
  for (int64_t i = 0; i < n; ++i) {
    cin >> c[i];
  }
  set<pair<int64_t, int64_t> > s;
  for (int64_t i = 1; i < MAX_COLOR + 1; ++i) {
    s.insert({0, i});
  }
  vector<int64_t> cnt(MAX_COLOR + 1);
  for (int64_t i = 0; i < n; ++i) {
    if (s.find({cnt[c[i]], c[i]}) != s.end()) {
      s.erase({cnt[c[i]], c[i]});
      ++cnt[c[i]];
      s.insert({cnt[c[i]], c[i]});
    }
    while (!s.empty() && s.begin()->first < cnt[a]) {
      s.erase(s.begin());
    }
  }
  if (s.size() == 1) {
    cout << -1 << endl;
  } else {
    if (s.begin()->second == a) {
      cout << (--s.end())->second;
    } else {
      cout << s.begin()->second;
    }
  }
  return 0;
}
