#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  vector<bool> p(1500001, true);
  p[0] = p[1] = false;
  for (int i = 2; i < 1500001; ++i)
    if (p[i])
      for (int j = 2 * i; j < 1500001; j += i) p[j] = false;
  int n, x;
  cin >> n >> x;
  if (x == 2) {
    cout << "0";
    return 0;
  }
  set<int> S;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    S.insert(a);
  }
  if (S.find(1) != S.end()) {
    cout << "1";
    return 0;
  }
  if (x > 1500000) {
    cout << "-1";
    return 0;
  }
  bool odp = true;
  int il = 0;
  for (int i = 2; i <= x - (x % 2); ++i) {
    if (p[i]) {
      if (S.find(i) != S.end())
        ++il;
      else
        odp = false;
    }
  }
  if (odp)
    cout << il;
  else
    cout << "-1";
  return 0;
}
