#include <bits/stdc++.h>
using namespace std;
int n, m, A, cont, colr[1000007];
vector<set<int> > mass(100007);
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> A;
  for (int i = 0; i < n; i++) {
    cin >> m;
    if (m == A) {
      for (std::set<int>::iterator j = mass[cont].begin();
           j != mass[cont].end(); j++) {
        colr[*j] = -1;
      }
      cont++;
    } else {
      if (colr[m] != -1) {
        mass[colr[m]].erase(m);
        colr[m]++;
        mass[colr[m]].insert(m);
        if (colr[m] <= cont) {
          colr[m] = -1;
        }
      }
    }
  }
  for (int i = 1; i <= 1000000; i++) {
    if (cont == 0) {
      if (colr[i] != -1 && i != A) {
        cout << i;
        return 0;
      }
    } else {
      if (colr[i] > 0 && i != A) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
