#include <bits/stdc++.h>
using namespace std;
int P[(2 << 20)];
int A[(2 << 20)];
int F(int x) {
  if (x == 2) return 0;
  if (A[1] != 0) return 1;
  int res = 0;
  int i;
  for (i = (0); i < (x); ++i)
    if (P[i] == -1) {
      if (A[i] == 0) return -1;
      ++res;
    }
  return res;
}
int main() {
  int i, j;
  memset(P, -1, sizeof(P));
  P[0] = P[1] = 0;
  for (i = (0); i < ((2 << 20)); ++i)
    if (P[i] == -1)
      for (j = i + i; j < (2 << 20); j += i) P[j] = 0;
  memset(A, 0, sizeof(A));
  int n, x;
  scanf("%d%d", &n, &x);
  for (i = (0); i < (n); ++i) {
    int a;
    scanf("%d", &a);
    if (a < (2 << 20)) A[a] = 1;
  }
  printf("%d\n", F(x));
  return 0;
};
