#include <bits/stdc++.h>
using namespace std;
constexpr int seed = 131;
constexpr long long LLMAX = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-8;
constexpr int MAXN = 1e6 + 10;
constexpr int hmod1 = 0x48E2DCE7;
constexpr int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inline double sqr(double x) { return x * x; }
inline int mul(int x, int y) { return 1ll * x * y % MOD; }
inline int sub(int x, int y) { return x >= y ? x - y : MOD + x - y; }
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return (x > 0 ? 1 : -1);
}
inline long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return sum;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d;
  (b == 0 ? (x = 1, y = 0, d = a)
          : (d = exgcd(b, a % b, y, x), y -= a / b * x));
  return d;
}
set<pair<int, int> > s, rs;
int a[MAXN];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, A;
  cin >> n >> A;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0, na = 0; i < n; i++) {
    if (a[i] == A) {
      na++;
      while (s.size() && s.begin()->first < na) {
        pair<int, int> p = *s.begin();
        s.erase(s.begin());
        rs.erase(rs.find({p.second, p.first}));
      }
      if (s.empty()) return cout << -1 << endl, 0;
    } else {
      auto it = rs.lower_bound({a[i], -1});
      if (it == rs.end() || it->first != a[i]) {
        if (na)
          continue;
        else {
          s.insert({1, a[i]});
          rs.insert({a[i], 1});
        }
      } else {
        pair<int, int> p = *it;
        rs.erase(it);
        s.erase(s.find({p.second, p.first}));
        p.second++;
        rs.insert({p.first, p.second});
        s.insert({p.second, p.first});
      }
    }
  }
  if (s.empty())
    cout << -1 << endl;
  else
    cout << s.begin()->second << endl;
  return 0;
}
