#include <bits/stdc++.h>
using namespace std;
int N, X, bound = sqrt(INT_MAX);
int A[100005], t, L;
vector<int> S;
bool prime[2000000 + 5];
int main() {
  scanf("%d%d", &N, &X);
  for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
  sort(A, A + N);
  if (X == 2)
    printf("0\n");
  else if (A[0] == 1)
    printf("1\n");
  else if (X >= 2000000) {
    printf("-1\n");
    return 0;
  } else {
    for (int i = 2; i <= 2000000; ++i)
      if (!prime[i]) {
        S.push_back(i);
        if (i <= bound)
          for (int j = i * i; j <= 2000000; j += i) prime[j] = 1;
      }
    L = S.size();
    for (int i = 0; i < L; ++i) {
      if (S[i] >= X) {
        printf("%d\n", i);
        return 0;
      }
      while (t < N && A[t] != S[i]) ++t;
      if (t == N) {
        printf("-1\n");
        return 0;
      }
    }
  }
}
