#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932385;
const long double E = 2.71828182845904523536;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1 << 30;
const int N = 1000100;
int frq[N];
int a[N];
set<pair<int, int>, greater<pair<int, int> > > s, temp;
bool rem[N];
int main() {
  int n, A;
  scanf("%d%d", &n, &A);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int cntA = 0;
  bool f = 1;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (rem[x]) continue;
    if (x != A) {
      if (frq[x]) {
        s.erase({frq[x], x});
        frq[x]++;
        s.insert({frq[x], x});
      } else {
        if (f) {
          frq[x]++;
          s.insert({frq[x], x});
        }
      }
    } else {
      f = 0;
      cntA++;
      if (a[i] != a[i + 1]) {
        for (auto y : s) {
          if (y.first >= cntA)
            temp.insert(y);
          else
            rem[y.second] = 1;
        }
        s.clear();
        s = temp;
        temp.clear();
      }
    }
  }
  if (s.size())
    printf("%d", (*s.begin()).second);
  else
    printf("-1");
  return 0;
}
