#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void read(int &x) {
  char c = nc(), b = 1;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
const int N = 5000005, mP = N / 10;
bool vst[N];
int prime[mP], num;
inline void Pre(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vst[i]) prime[++num] = i;
    for (int j = 1; j <= num && (long long)prime[j] * i <= n; j++) {
      vst[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
int tag[N], a[N];
int main() {
  int n, x;
  read(n);
  read(x);
  int flag = 0;
  for (int i = 1; i <= n; i++) read(a[i]), flag |= a[i] == 1;
  if (flag && x > 2) return printf("1\n"), 0;
  if (x > 5e6) return printf("-1\n"), 0;
  Pre(x);
  for (int i = 1; i <= n; i++)
    if (a[i] <= x) tag[a[i]] = 1;
  int cnt = 0;
  for (int i = 1; i <= num && prime[i] < x; i++)
    if (!tag[prime[i]])
      return printf("-1\n"), 0;
    else
      cnt++;
  printf("%d\n", cnt);
  return 0;
}
