#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, MAXA = 5e6 + 5;
int n, x;
int a[MAXN];
bool seen[MAXA];
bitset<MAXA> notPrime;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int answer = 0;
  cin >> n >> x;
  if (x == 2) {
    cout << "0" << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < MAXA) seen[a[i]] = true;
    if (a[i] == 1) {
      cout << "1" << '\n';
      return 0;
    }
  }
  if (x > MAXA) {
    cout << "-1" << '\n';
    return 0;
  }
  notPrime.reset();
  for (long long i = 2; i < MAXA; i++) {
    if (notPrime[i] == true) continue;
    for (long long j = i * i; j < MAXA; j += i) {
      notPrime[j] = true;
    }
  }
  for (int i = 2; i < x; i++) {
    if (notPrime[i] == false) {
      if (seen[i] == true)
        answer++;
      else {
        answer = -1;
        break;
      }
    }
  }
  cout << answer << '\n';
}
