#include <bits/stdc++.h>
using namespace std;
int n, al;
vector<int> col, mat, hash2;
void func(int st, int en, int val) {
  for (int i = st; i <= en; i++) {
    int num = col[i];
    if (hash2[num] >= val)
      hash2[num]++;
    else
      hash2[num] = -1;
  }
}
int main() {
  scanf("%d %d", &n, &al);
  col.resize(n);
  hash2.resize(1000007, 0);
  int ind = -1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &col[i]);
    if (col[i] == al) mat.push_back(i);
    if (col[i] == al && ind == -1) ind = i;
  }
  if (ind == -1) {
    if (al == 1)
      printf("2\n");
    else
      printf("1\n");
  } else if (ind - 1 == -1) {
    printf("-1\n");
  } else {
    int prev = 0, cur;
    for (int i = 0; i < mat.size(); i++) {
      cur = mat[i];
      func(prev, cur - 1, i);
      prev = cur + 1;
    }
    int sz = mat.size(), ans = -1;
    for (int i = 0; i <= 1000000; i++) {
      if (hash2[i] >= sz) {
        ans = i;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
