#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  long long n, a;
  cin >> n >> a;
  set<pair<long long, long long> > st;
  map<long long, long long> mp;
  vector<long long> s(n);
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<long long> vis(1e6 + 5, 0);
  long long i = 0;
  for (; i < n; i++) {
    if (s[i] == a) {
      break;
    }
    vis[s[i]] = 1;
    mp[s[i]]++;
  }
  for (auto z : mp) {
    st.insert({z.second, z.first});
  }
  long long cnt = 0;
  for (long long j = i; j < n; j++) {
    if (s[j] == a) {
      cnt++;
      auto it = st.lower_bound({cnt, 0});
      if (it == st.end()) {
        cout << -1 << endl;
        return;
      } else {
        for (auto z : st) {
          if (z.first == it->first) {
            break;
          }
          vis[z.second] = 0;
        }
        if (it != st.begin()) st.erase(st.begin(), prev(it));
      }
    } else if (vis[s[j]] == 1) {
      st.erase({mp[s[j]], s[j]});
      mp[s[j]]++;
      st.insert({mp[s[j]], s[j]});
    }
  }
  cout << prev(st.end())->second << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long test = 1;
  while (test--) solve();
}
