#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
int n, k;
int a[102400];
int p[202400];
bool b[2024000];
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  memset((b), 0, sizeof(b));
  for (int i = (2); i <= (int)(10000); i++) {
    if (b[i]) continue;
    int j = i * i;
    while (j <= 2000000) {
      b[j] = true;
      j += i;
    }
  }
  int cnt = 0;
  for (int i = (2); i <= (int)(2000000); i++) {
    if (!b[i]) {
      p[cnt++] = i;
    }
  }
  scanf("%d%d", &n, &k);
  if (k == 2) {
    puts("0");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int x;
    scanf("%d", &x);
    if (x > 2000000) continue;
    if (x == 1) {
      puts("1");
      return 0;
    }
    if (!b[x] && x <= k - 1) {
      b[x] = true;
      ans++;
    }
  }
  for (int i = (2); i <= (int)(k - 1); i++) {
    if (!b[i]) {
      puts("-1");
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
