#include <bits/stdc++.h>
using namespace std;
int main() {
  bool prime[2000001];
  for (int i = 0; i < (2000001); i++) prime[i] = true;
  for (int j = 2; j <= 2000000; j++)
    if (prime[j]) {
      for (int i = 2 * j; i <= 2000000; i += j) prime[i] = false;
    }
  int N, first;
  scanf("%d%d", &N, &first);
  int A[N];
  for (int i = 0; i < (N); i++) scanf("%d", &A[i]);
  if (first == 2) {
    printf("0\n");
    return 0;
  }
  bool _is[2000000];
  for (int i = 0; i < (2000000); i++) _is[i] = false;
  for (int i = 0; i < (N); i++)
    if (A[i] < 2000000) _is[A[i]] = true;
  if (_is[1]) {
    printf("1\n");
    return 0;
  }
  if (first > 2000000) {
    printf("-1\n");
    return 0;
  }
  int result = 0;
  for (int i = 2; i < first; i++)
    if (prime[i])
      if (_is[i])
        result++;
      else {
        printf("-1\n");
        return 0;
      }
  printf("%d\n", result);
}
