#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long powmodM(long long a, long long b, long long c = M) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % M;
    a = (a * a) % M;
    b /= 2;
  }
  return res;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b /= 2;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (a && b) a > b ? a %= b : b %= a;
  return a + b;
}
long long lcm(long long a, long long b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
vector<long long int> sieve(long long int n) {
  vector<long long int> ans, prime(2 * 1e6);
  prime[0] = false;
  prime[1] = false;
  for (long long int p = 2; p * p <= n; p++)
    if (prime[p])
      for (long long int i = p * p; i <= n; i += p) prime[i] = 0;
  for (long long p = (2); p <= (n); ++p)
    if (prime[p]) ans.push_back(p);
  return ans;
}
long long modInverse(long long n, long long p = M) {
  return powmodM(n, p - 2, p);
}
long long nCrModP(long long n, long long r, long long p = M) {
  if (r == 0) return 1;
  long long fac[n + 1];
  fac[0] = 1;
  for (long long i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
double pie = 3.14159265358979323846264338;
const long long int INF = 0x3f3f3f3f;
class l {
 public:
  char data;
  l *next;
  l *prev;
  l(char a) {
    data = a;
    prev = NULL;
    next = NULL;
  }
};
map<long long int, long long int> fre;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> arr(n);
  for (long long i = (0); i <= (n - 1); ++i) cin >> arr[i];
  if (m == arr[0]) {
    cout << -1;
    return 0;
  }
  long long int ma = 0;
  fre[arr[ma]] = 1;
  bool ok = 1;
  long long int uski = 0;
  for (long long i = (1); i <= (n - 1); ++i) {
    if (arr[i] == m) {
      uski++;
      vector<long long int> re;
      for (auto u : fre) {
        if (u.second < uski) re.push_back(u.first);
      }
      for (auto u : re) {
        fre.erase(u);
      }
      if (!fre.size()) {
        cout << -1;
        return 0;
      }
    }
    if (!uski)
      fre[arr[i]]++;
    else if (fre[arr[i]]) {
      fre[arr[i]]++;
    }
  }
  vector<long long int> re;
  for (auto u : fre) {
    if (u.second < uski) re.push_back(u.first);
  }
  for (auto u : re) {
    fre.erase(u);
  }
  if (!fre.size()) {
    cout << -1;
    return 0;
  }
  if (fre.size()) {
    cout << fre.begin()->first;
  } else {
    cout << -1;
  }
}
