#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500000;
bool pres[MAXN], prime[MAXN];
int main() {
  fill(prime, prime + MAXN, true);
  prime[0] = prime[1] = false;
  vector<int> p;
  for (long long int i = 2; i * i < MAXN; i++)
    if (prime[i]) {
      for (long long int j = i * i; j < MAXN; j += i) prime[j] = false;
    }
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    if (a < MAXN) pres[a] = true;
  }
  int res;
  if (x == 2)
    res = 0;
  else if (pres[1])
    res = 1;
  else if (x >= MAXN)
    res = -1;
  else {
    res = 0;
    for (int i = (int)(2); i < ((int)x); i++)
      if (prime[i]) {
        if (!pres[i]) {
          res = -1;
          break;
        } else
          res++;
      }
  }
  cout << res << endl;
  return 0;
}
