#include <bits/stdc++.h>
using namespace std;
class comp {
 public:
  bool operator()(pair<int, int> &a, pair<int, int> &b) {
    return a.second > b.second;
  }
};
int col[1000001] = {0};
bool ans[1000001];
int main() {
  int n, a;
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> a;
  int na = 0, c;
  priority_queue<pair<int, int>, vector<pair<int, int> >, comp> myQueue;
  for (int i = 1; i <= 1000000; i++) {
    ans[i] = true;
    if (i == a) continue;
    myQueue.push(make_pair(i, 0));
  }
  for (int i = 1; i <= n; i++) {
    cin >> c;
    if (c == a) {
      na++;
    } else {
      col[c]++;
      myQueue.push(make_pair(c, col[c]));
    }
    while (!myQueue.empty()) {
      pair<int, int> y = myQueue.top();
      if (y.second >= na) break;
      myQueue.pop();
      if (col[y.first] != y.second) {
        continue;
      } else {
        ans[y.first] = false;
      }
    }
  }
  for (int i = 1; i <= 1000000; i++) {
    if (i == a) continue;
    if (ans[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
