#include <bits/stdc++.h>
using namespace std;
int primeSieve(int factor[], int prime[], int n) {
  int top = 0;
  memset(factor, 0, sizeof(int) * (n + 1));
  for (int i = 2; i <= n; i++) {
    if (0 == factor[i]) prime[top++] = i;
    for (int j = 0; j < top && prime[j] * i <= n; j++) {
      factor[prime[j] * i] = prime[j];
      if (0 == (i % prime[j])) break;
    }
  }
  return top;
}
const int N = 3000000;
int factor[N], prime[N];
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  if (x >= N) {
    for (int i = 0; i < n; i++) {
      int a;
      scanf("%d", &a);
      if (a == 1) {
        cout << 1 << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  if (x == 2) {
    cout << 0 << endl;
    return 0;
  }
  int top = primeSieve(factor, prime, x - 1);
  set<int> all(prime, prime + top);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (all.count(a)) {
      all.erase(all.find(a));
    }
    if (a == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << (all.empty() ? top : -1) << endl;
  return 0;
}
