#include <bits/stdc++.h>
using namespace std;
int tot;
int a[100010], pri[200000];
bool del[2000010];
void Init() {
  tot = 0;
  for (int i = 2; i <= 2000000; i++) {
    if (!del[i]) pri[tot++] = i;
    for (int j = 0; j < tot && pri[j] * i <= 2000000; j++) {
      del[pri[j] * i] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
int main() {
  Init();
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  if (x == 2)
    puts("0");
  else if (n == 0)
    puts("-1");
  else if (n > 0 && a[0] == 1)
    puts("1");
  else {
    int m = 0;
    for (int i = 0; i < n; i++)
      if (a[i] <= 2000000 && !del[a[i]] && (i == 0 || a[i] != a[i - 1]))
        a[m++] = a[i];
    n = m;
    for (m = 0; m < n && a[m] == pri[m]; m++)
      ;
    for (int i = 0; i <= m; i++)
      if (pri[i] >= x) {
        printf("%d\n", i);
        return 0;
      }
    puts("-1");
  }
  return 0;
}
