#include <bits/stdc++.h>
using namespace std;
int n, m, ans, a[100005], p[150000];
bool vis[2000005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)1, _y = n; i <= _y; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  n = unique(a + 1, a + n + 1) - (a + 1);
  if (m == 2) return puts("0"), 0;
  if (n == 0) return puts("-1"), 0;
  if (a[1] == 1) return puts("1"), 0;
  if (m > 20 * n) return puts("-1"), 0;
  vis[1] = 1;
  for (int i = (int)2, _y = m - 1; i <= _y; i++) {
    if (!vis[i]) p[++*p] = i;
    for (int j = 1; j <= *p && p[j] * i <= m; j++) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 1, j = 1; i <= *p; i++) {
    for (; j <= n && a[j] < p[i]; j++)
      ;
    if (a[j] != p[i]) return puts("-1"), 0;
    j++;
    ans++;
  }
  printf("%d\n", ans);
}
