#include <bits/stdc++.h>
using namespace std;
long long xp[2000060];
int main() {
  long long n, a;
  cin >> n >> a;
  map<long long, long long> mp;
  long long i, x;
  long long ok = 1, mx = 0, ans;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (mp[x] < mp[a]) xp[x] = -1;
    mp[x]++;
    if (x != a and xp[x] != -1) {
      mx = max(mx, mp[x]);
      if (mx == mp[x]) ans = x;
    } else if (mp[a] > mx)
      ok = 0;
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
