#include <bits/stdc++.h>
using namespace std;
const int N = 1299827;
vector<int> primes;
bool ppp[N];
void pre() {
  for (int n = 2; n < N; n++) {
    ppp[n] = true;
  }
  for (int n = 2; n < N; n++) {
    if (ppp[n]) {
      primes.push_back(n);
      if (n * 1LL * n >= N) continue;
      for (int m = n * n; m < N; m += n) {
        ppp[m] = false;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  pre();
  int n, x;
  cin >> n >> x;
  set<int> st;
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    st.insert(y);
  }
  if (x == 2) {
    cout << 0;
    exit(0);
  }
  if (st.count(1)) {
    cout << 1;
    exit(0);
  }
  if (x >= N) {
    cout << -1;
    exit(0);
  }
  int ans = 0;
  for (int pr : primes) {
    if (pr >= x) break;
    if (!st.count(pr)) {
      cout << -1;
      exit(0);
    }
    ++ans;
  }
  cout << ans;
  return 0;
}
