#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n, x, pr;
bool sieve[6000100];
int main() {
  scanf("%d%d", &n, &x);
  if (x == 2) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  if (!v.empty() && v[0] == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (x > 6000000) {
    cout << -1 << endl;
    return 0;
  }
  sieve[2] = 0;
  for (int i = 2; i < x; i++) {
    if (sieve[i] == 0) {
      int f = i + i;
      while (f <= x) {
        sieve[f] = 1;
        f += i;
      }
      pr++;
      if (binary_search(v.begin(), v.end(), i) != 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << pr << endl;
  return 0;
}
