#include <bits/stdc++.h>
const int MAXN = 2000000 + 10;
bool notp[MAXN], c[MAXN];
int main() {
  int i, j, x;
  int n, m, pn = 0;
  scanf("%d %d", &n, &m);
  if (m == 2) {
    printf("0\n");
    return 0;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x >= MAXN) continue;
    c[x] = true;
    if (x == 1) {
      printf("1\n");
      return 0;
    }
  }
  if (m >= MAXN) {
    printf("-1\n");
    return 0;
  }
  for (i = 2; i < m; i++) {
    if (!notp[i]) {
      pn++;
      for (j = i * 2; j < m; j += i) notp[j] = true;
    }
  }
  for (i = 2; i < m; i++) {
    if (!notp[i] and !c[i]) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", pn);
  return 0;
}
