#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 1001, M = 1600000;
int cnt, n, m, x;
char p[M + 5555];
set<int> s;
int main() {
  cin >> n >> m;
  m = min(m, M);
  for (int i = 1; i <= n; i++) {
    cin >> x;
    s.insert(x);
  }
  if (m == 2) {
    cout << 0;
    return 0;
  }
  if (s.count(1)) {
    cout << 1;
    return 0;
  }
  if (m == 3) {
    if (s.count(2))
      cout << 1;
    else
      cout << -1;
    return 0;
  }
  for (int i = 2; i < m; i++) {
    if (!p[i]) {
      if (!s.count(i)) {
        return cout << -1, 0;
      }
      ++cnt;
      for (int j = i + i; j <= m; j += i) p[j] = 1;
    }
  }
  cout << cnt;
}
