#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000005;
bool pp[maxn];
vector<int> p;
int a[maxn];
set<int> h;
int n, x;
int main() {
  for (int i = 0; i < (maxn); ++i) pp[i] = true;
  for (int i = 2; i * i < maxn; ++i) {
    if (!pp[i]) continue;
    for (int j = i + i; j < maxn; j += i) pp[j] = false;
  }
  scanf("%d %d", &n, &x);
  if (x == 2) {
    printf("0\n");
    return 0;
  }
  for (int i = 2; i < maxn; ++i)
    if (pp[i]) {
      if (int((p).size()) > n + 5) break;
      p.push_back(i);
    }
  for (int i = 0; i < (n); ++i) {
    int x;
    scanf("%d", &x);
    h.insert(x);
  }
  if (h.find(1) != h.end()) {
    printf("%d\n", 1);
    return 0;
  }
  int ok = 1, cnt = 0;
  for (int i = 0; x - 1 >= p[i]; ++i) {
    if (h.find(p[i]) == h.end()) {
      ok = 0;
      break;
    }
    ++cnt;
  }
  if (ok)
    printf("%d\n", cnt);
  else
    printf("%d\n", -1);
  return 0;
}
