#include <bits/stdc++.h>
using namespace std;
const int nmax = 10000100;
bool b[nmax];
bool c[nmax];
void sieve() {
  memset(b, 0, sizeof(b));
  for (int i = 2; i < nmax; ++i) {
    if (!b[i]) {
      for (int j = i << 1; j < nmax; j += i) {
        b[j] = true;
      }
    }
  }
}
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  if (x == 2) {
    puts("0");
    return 0;
  }
  sieve();
  memset(c, 0, sizeof(c));
  int t;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    if (t < nmax) {
      c[t] = true;
    }
  }
  if (c[1]) {
    puts("1");
    return 0;
  }
  int ans = 0;
  for (int i = 2; i < x; ++i) {
    if (!b[i]) {
      if (!c[i]) {
        ans = -1;
        break;
      }
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}
