#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
const int CNT = 13 * 1000 * 1000;
bool p[CNT];
int n, a[100100];
long long x;
bool prime(int x) {
  if (x >= CNT) return false;
  return p[x];
}
int main() {
  memset(p, 1, sizeof p);
  p[0] = p[1] = false;
  for (long long i = 2; i < CNT; i++)
    if (p[i])
      for (long long j = i * i; j < CNT; j += i) p[j] = false;
  cin >> n >> x;
  for (int i = 0; i < (int)(n); i++) scanf("%d", &a[i]);
  set<int> st(a, a + n);
  if (x == 2) {
    cout << 0 << endl;
    return 0;
  }
  if (!st.empty() && *st.begin() == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<int> t;
  for (int i = 0; i < (int)(min(CNT, (int)x)); i++)
    if (p[i]) t.push_back(i);
  if (x >= CNT) t.push_back(-1);
  for (int i = 0; i < (int)(t.size()); i++)
    if (!st.count(t[i])) {
      cout << -1 << endl;
      return 0;
    }
  cout << t.size() << endl;
  return 0;
}
