#include <bits/stdc++.h>
using namespace std;
const int DIM = 3000005;
set<int> mst;
bitset<DIM> oki;
int main(void) {
  int n, x;
  scanf("%d %d", &n, &x);
  if (x == 2) {
    printf("%d\n", 0);
    return 0;
  }
  for (int i = 2; i < DIM; ++i)
    if (!oki[i])
      for (int j = i + i; j < DIM; j += i) oki[j] = true;
  for (int i = 1; i <= n; ++i) {
    int v;
    scanf("%d", &v);
    if (v == 1) {
      printf("%d\n", 1);
      return 0;
    }
    mst.insert(v);
  }
  int ans = 0;
  for (int i = 2; i < x; ++i)
    if (!oki[i]) {
      if (mst.find(i) == mst.end()) {
        printf("%d\n", -1);
        return 0;
      } else
        ++ans;
    }
  printf("%d\n", ans);
  return 0;
}
