#include <bits/stdc++.h>
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1e6 + 10;
int cnt[MR];
bool done[MR];
int main() {
  int n, A;
  scanf("%d%d", &n, &A);
  set<pair<int, int>> S;
  int lim = 1e6;
  for (int i = (1); i <= (lim); ++i)
    if (i != A)
      S.insert(make_pair(0, i));
    else
      S.insert(make_pair(0, -A));
  for (int i = 0; i < (n); ++i) {
    int c;
    scanf("%d", &c);
    if (done[c]) continue;
    if (c != A) {
      S.erase(make_pair(cnt[c], c));
      cnt[c]++;
      S.insert(make_pair(cnt[c], c));
    } else {
      S.erase(make_pair(cnt[c], -A));
      cnt[c]++;
      S.insert(make_pair(cnt[c], -A));
      auto it = S.find(make_pair(cnt[A], -A));
      vector<pair<int, int>> rem;
      while (it != S.begin()) {
        it--;
        rem.push_back(*it);
      }
      for (auto p : rem) {
        done[p.second] = 1;
        S.erase(p);
      }
    }
    if (S.size() == 1) {
      printf("-1\n");
      return 0;
    }
  }
  auto it = S.begin();
  it++;
  printf("%d\n", it->second);
  return 0;
}
