#include <bits/stdc++.h>
int pn;
int dv[2000000 + 5];
int a[100000 + 5];
int prime[100000 + 5];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  std::sort(a, a + n);
  if (x == 2) {
    printf("0\n");
    return 0;
  }
  if (a[0] == 1) {
    printf("1\n");
    return 0;
  }
  x--;
  for (int i = 2; i <= 2000000; i++) {
    if (dv[i] == 0) {
      prime[pn++] = i;
      if (pn > n || i > x) break;
      for (int j = i; j <= 2000000; j = j + i) {
        dv[j] = 1;
      }
    }
  }
  if (prime[pn - 1] < x)
    printf("-1\n");
  else {
    while (prime[pn - 1] > x && pn > 0) pn--;
    int p = 0, flag = 1;
    for (int i = 0; i < n; i++) {
      if (prime[p] == a[i] && p < pn) p++;
    }
    if (p < pn) flag = 0;
    if (flag == 0)
      printf("-1\n");
    else
      printf("%d\n", pn);
  }
  return 0;
}
