#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int MAX_NUMBER = 25 * 1000 * 1000;
const int ROOT = 10000;
bool isPrime[MAX_NUMBER];
int primesAmount;
bool canMult(int a, int b) {
  if (b == 0) {
    return true;
  }
  return a <= MAX_NUMBER / b;
}
void precalc() {
  int op = 0;
  memset(isPrime, true, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  primesAmount = 0;
  double t = clock();
  for (int i = 2; i < MAX_NUMBER; ++i) {
    ++op;
    if (isPrime[i]) {
      ++primesAmount;
      if (i < ROOT) {
        for (int j = i * i; j < MAX_NUMBER; j += i) {
          ++op;
          isPrime[j] = false;
        }
      }
    }
  }
  cerr << "op " << op << endl;
  cerr << "amount primes " << primesAmount << endl;
  t = clock() - t;
  t /= CLOCKS_PER_SEC;
  cerr << "precalc time is " << t << endl;
}
int solve(int x, const vector<int>& a) {
  if (x == 2) {
    return 0;
  }
  vector<bool> haveNumber(MAX_NUMBER, false);
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] < MAX_NUMBER) {
      haveNumber[a[i]] = true;
    }
  }
  if (haveNumber[1]) {
    return 1;
  }
  int primesToX = 0;
  for (int i = 2; i <= x - 1; ++i) {
    if (isPrime[i]) {
      ++primesToX;
      if (!haveNumber[i]) {
        return -1;
      }
    }
  }
  return primesToX;
}
int main() {
  precalc();
  int n, x;
  while (cin >> n >> x) {
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int res = solve(x, a);
    cout << res << endl;
  }
  return 0;
}
