#include <bits/stdc++.h>
using namespace std;
const int L = 2e6;
const int S = 1e5;
int a[S];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int c = 0;
  int k = 0;
  if (x == 2) {
    puts("0");
    return 0;
  } else if (a[0] == 1) {
    puts("1");
    return 0;
  }
  vector<bool> done(L);
  for (long long i = 2; i < x; i++) {
    if (!done[i]) {
      while (k < n && i != a[k]) {
        k++;
      }
      if (k < n) {
        c++;
        for (long long j = i * i; j < done.size(); j += i) {
          done[j] = true;
        }
      } else {
        puts("-1");
        return 0;
      }
    }
  }
  printf("%d\n", c);
  return 0;
}
