#include <bits/stdc++.h>
using namespace std;
int n, xx;
map<int, int> ori, ad;
int a[100005];
inline int rd() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  return x;
}
int main() {
  n = rd();
  xx = rd();
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; ++i) {
    a[i] = rd();
    ori[a[i]]++;
    ad[(a[i] & xx)]++;
  }
  for (int i = 1; i <= n; ++i) {
    if (ori[a[i]] > 1) {
      ans = min(ans, 0);
    }
    ori[a[i]]--;
    if (ori[(a[i] & xx)]) {
      ans = min(ans, 1);
    }
    ori[a[i]]++;
    if (ad[(a[i] & xx)] > 1) {
      ans = min(ans, 2);
    }
  }
  if (ans < 0x3f3f3f3f)
    printf("%d\n", ans);
  else
    puts("-1");
  return 0;
}
