#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long Mod = 1e9 + 7;
const int N = 1e5 + 7;
int A[N], c, n;
vector<int> Col[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> c;
  map<int, int> ok, rev;
  ok[c];
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    ok[A[i]];
  }
  int id = 1;
  for (auto it : ok) {
    rev[id] = it.first;
    ok[it.first] = id++;
  }
  for (int i = 1; i <= n; i++) {
    A[i] = ok[A[i]];
    Col[A[i]].push_back(i);
  }
  c = ok[c];
  for (int i = 1; i < N; i++) {
    if (i == c || Col[i].size() < Col[c].size()) continue;
    int id1 = 0;
    bool ok = true;
    for (int j = 0; j < Col[i].size(); j++) {
      while (id1 < Col[c].size() && Col[i][j] > Col[c][id1]) id1++;
      if (j + 1 <= id1) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << rev[i] << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
