#include <bits/stdc++.h>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const long long maxn = 2e6 + 100;
const long long inf = 1e9 + 800;
const long long mod = 1e9 + 7;
set<long long> st;
bitset<maxn> nis_pr;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n >> x;
  if (x == 2) {
    cout << 0;
    return 0;
  }
  x--;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    st.insert(a);
  }
  if (st.find(1) != st.end()) {
    cout << 1;
    return 0;
  }
  if (x > 1300000) {
    cout << -1;
    return 0;
  }
  long long ans = 0;
  for (long long i = 2; i <= x; i++) {
    if (!nis_pr[i]) {
      if (st.find(i) == st.end()) {
        cout << -1;
        return 0;
      }
      ans++;
      for (long long j = i * i; j <= x; j += i) {
        nis_pr[j] = 1;
      }
    }
  }
  cout << ans;
}
