#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, x, bac[maxn], a[maxn], b[maxn];
inline int read() {
  char ch = getchar();
  int u = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    u = u * 10 + ch - 48;
    ch = getchar();
  }
  return u * f;
}
int main() {
  n = read();
  x = read();
  for (register int i = 1; i <= n; i++) {
    a[i] = read();
    b[i] = a[i] & x;
    if (bac[a[i]]) {
      printf("0");
      return 0;
    } else
      bac[a[i]] = 1;
  }
  for (register int i = 1; i <= n; i++) {
    bac[a[i]] = 0;
    if (bac[b[i]]) {
      cout << 1;
      return 0;
    } else
      bac[a[i]] = 1;
  }
  memset(bac, 0, sizeof(bac));
  for (register int i = 1; i <= n; i++) {
    if (bac[b[i]]) {
      cout << 2;
      return 0;
    } else
      bac[b[i]] = 1;
  }
  cout << -1;
  return 0;
}
