#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
char c;
inline void read(long long &a) {
  a = 0;
  do c = getchar();
  while (c < '0' || c > '9');
  while (c <= '9' && c >= '0') a = (a << 3) + (a << 1) + c - '0', c = getchar();
}
long long a[100001];
long long P[100001];
const int MAXN = 2233333;
int Tot, prime[MAXN + 1];
bool ck[MAXN + 1];
bool Has[MAXN + 1];
int main() {
  for (int i = 2; i <= MAXN; i++) {
    if (!ck[i]) prime[++Tot] = i;
    for (int j = 1, k = 2 * i; j <= Tot && k <= MAXN; k = prime[++j] * i) {
      ck[k] = true;
      if (i % prime[j] == 0) break;
    }
  }
  long long n, x;
  read(n), read(x);
  for (int i = 1; i <= n; i++) read(a[i]), Has[a[i] > MAXN ? 0 : a[i]] = true;
  sort(a + 1, a + 1 + n);
  n = unique(a + 1, a + 1 + n) - a - 1;
  if (x == 2) {
    return puts("0"), 0;
  }
  if (a[1] == 1) {
    return puts("1"), 0;
  }
  if (a[1] != 2) {
    return puts("-1"), 0;
  }
  if (x == 3) {
    return puts("1"), 0;
  }
  if (a[2] != 3) {
    return puts("-1"), 0;
  }
  if (n == 1) {
    return puts("-1"), 0;
  }
  if (prime[n + 1] < x) {
    return puts("-1"), 0;
  }
  int tot = 0;
  for (int i = 1; prime[i] < x; i++) {
    if (!Has[prime[i]]) {
      return puts("-1"), 0;
    }
    tot++;
  }
  cout << tot << endl;
  return 0;
}
