#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
long long mul(long long a, long long b) {
  if (a * b / a != b) return 1000000000000000007LL;
  return min(1000000000000000007LL, a * b);
}
bool isPrime[2000005];
set<int> s;
int n, x;
int main() {
  memset(isPrime, true, sizeof isPrime);
  for (int i = (2); i <= (sqrt(2000005)); ++i) {
    for (int j = i * i; j <= 2000005; j += i) isPrime[j] = false;
  }
  scanf("%d%d", &n, &x);
  for (int i = (1); i <= (n); ++i) {
    int x;
    scanf("%d", &x);
    s.insert(x);
  }
  if (x == 2)
    puts("0");
  else if (s.find(1) != s.end())
    puts("1");
  else {
    int cnt = 0;
    for (int p = (2); p <= (2000005 - 1); ++p) {
      if (isPrime[p]) {
        if (p >= x) break;
        if (s.find(p) == s.end()) {
          puts("-1");
          return 0;
        } else
          ++cnt;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
