#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (T x : p) os << x << " ";
  os << "]" << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const map<Tk, Tv>& p) {
  os << "{ ";
  for (pair<Tk, Tv> x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n & 1) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n & 1) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
map<int, set<int> > m;
int b[1000005];
map<int, set<int> >::iterator it;
int aux[1000005], auxl = 0;
int main() {
  int i, j;
  int n, a;
  scanf("%d", &n), scanf("%d", &a);
  for (i = 1; i < n + 1; i++)
    if (i != a) m[0].insert(i);
  int x = 0;
  for (i = 1; i < n + 1; i++) {
    scanf("%d", &j);
    if (j == a) {
      x++;
      auxl = 0;
      for (it = m.begin(); it != m.end() && (*it).first < x; it++)
        aux[auxl++] = (*it).first;
      for (j = 0; j < auxl; j++) m.erase(aux[j]);
    } else {
      if (b[j] >= x) {
        m[b[j]].erase(j);
        m[b[j] + 1].insert(j);
        if (m[b[j]].size() == 0) m.erase(b[j]);
        b[j]++;
      }
    }
  }
  for (it = m.begin(); it != m.end(); it++)
    if ((*it).first >= x && m[(*it).first].size() > 0) {
      int ind = (*it).first;
      printf("%d\n", *(m[ind]).begin());
      return 0;
    }
  puts("-1");
  return 0;
}
