#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20, MAX2 = 1e7 + 10;
int an[MAX], n, x;
bool primes[MAX2];
void seive(long long n) {
  for (long long i = 2; i <= n; i++) primes[i] = 1;
  for (long long i = 2; i <= n; i++) {
    if (primes[i] == 1) {
      for (long long j = i * i; j <= n; j += i) primes[j] = 0;
    }
  }
}
set<int> mm;
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) scanf("%d", &an[i]), mm.insert(an[i]);
  int k = 1299721;
  seive(k);
  if (x == 2)
    printf("%d\n", 0);
  else if (*mm.begin() == 1)
    printf("%d\n", 1);
  else {
    if (x - 1 > 1299721)
      printf("%d\n", -1);
    else {
      vector<int> pp;
      for (int i = 2; i <= x - 1; i++) {
        if (primes[i] == 1) pp.push_back(i);
      }
      bool ok = 1;
      for (int i = 0; i < pp.size(); i++) {
        auto ite = mm.find(pp[i]);
        if (ite == mm.end()) ok = 0;
      }
      if (!ok)
        printf("%d\n", -1);
      else
        printf("%d\n", pp.size());
    }
  }
  return 0;
}
