#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
template <typename T, typename T2>
inline void _max(T &a, T2 b) {
  a = max((T)a, (T)b);
}
template <typename T, typename T2>
inline void _min(T &a, T2 b) {
  a = min((T)a, (T)b);
}
const int MAX = 1e5 + 10, MAXC = 1e6 + 10;
int n, A, c[MAX];
int lvl[MAXC];
void clear() { memset(lvl, 0, sizeof(lvl)); }
void read() {
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
}
void solve() {
  map<int, set<int>> m;
  for (int i = 1; i <= 1000000; i++)
    if (i != A) m[0].insert(i);
  lvl[A] = -1;
  int lvlA = 0;
  for (int i = 0; i < n; i++)
    if (c[i] != A) {
      if (lvl[c[i]] == -1) continue;
      m[lvl[c[i]]].erase(c[i]);
      m[lvl[c[i]] + 1].insert(c[i]);
      lvl[c[i]]++;
    } else {
      for (auto &clr : m[lvlA]) lvl[clr] = -1;
      m.erase(lvlA);
      lvlA++;
    }
  for (int i = 1; i <= 1000000; i++)
    if (lvl[i] != -1) return void(printf("%d\n", i));
  printf("-1\n");
}
int main() {
  while (scanf("%d%d", &n, &A) == 2) {
    clear();
    read();
    solve();
    return 0;
  }
  return 0;
}
