#include <bits/stdc++.h>
using namespace std;
bool vis[1000010], fail[1000010];
int c[100010], cnt[1000010], al;
set<pair<int, int>> st;
set<pair<int, int>>::iterator it;
int main() {
  ios_base::sync_with_stdio(false);
  int n, a;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    if (!vis[c[i]] && c[i] != a) {
      st.insert(make_pair(0, c[i]));
      vis[c[i]] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (fail[c[i]]) continue;
    if (c[i] == a) {
      al++;
      for (it = st.begin(); it != st.end();) {
        if ((*it).first < al) {
          fail[(*it).second] = true;
          st.erase(it++);
        } else
          break;
      }
    } else {
      st.erase(st.find(make_pair(cnt[c[i]], c[i])));
      cnt[c[i]]++;
      st.insert(make_pair(cnt[c[i]], c[i]));
    }
    if (st.empty()) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << (*st.rbegin()).second << endl;
  return 0;
}
