#include <bits/stdc++.h>
int LIM = 1300001;
int n, m, a[1300001], x, g[1300001], dx;
int main() {
  for (int i = 2; i <= LIM; i++) {
    if (!a[i]) {
      x++;
      for (int j = 2; i * j <= LIM; j++) a[i * j] = 1;
    }
  }
  a[1] = 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x < LIM) g[x] = 1;
  }
  if (m == 2)
    printf("0\n");
  else if (g[1])
    printf("1\n");
  else {
    x = 0;
    for (int i = 2; i <= m; i++) {
      if (!a[i - 1]) {
        if (g[i - 1])
          x++;
        else {
          printf("-1\n");
          goto ff;
        }
      }
    }
    printf("%d\n", x);
  ff:;
  }
  return 0;
}
