#include <bits/stdc++.h>
using namespace std;
const int lim = 1299721;
bool is_prime[lim + 1];
vector<int> p;
int main() {
  memset(is_prime, true, sizeof(is_prime));
  for (int i = 2; i <= lim; ++i) {
    if (is_prime[i]) {
      p.push_back(i);
      if (i <= lim / i)
        for (int j = i * i; j <= lim; j += i) is_prime[j] = false;
    }
  }
  int n, x;
  scanf("%d %d", &n, &x);
  if (x == 2)
    printf("0\n");
  else if (n == 0)
    printf("-1\n");
  else {
    int a[n];
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a, a + n);
    if (a[0] == 1)
      printf("1\n");
    else if (x > lim)
      printf("-1\n");
    else {
      set<int> S(a, a + n);
      int ans = 0;
      for (int i = 0; p[i] < x && ans != -1; ++i) {
        if (S.find(p[i]) != S.end())
          ++ans;
        else
          ans = -1;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
