#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> d;
  m = 1000000000;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    d[x]++;
    m = min(m, x);
  }
  if (d[m] < 2) cout << -1 << endl;
}
