#include <bits/stdc++.h>
using namespace std;
set<int64_t> s1, s2;
int main() {
  int64_t n, m, x, t;
  scanf("%I64d", &n);
  m = n;
  scanf("%I64d", &x);
  for (int64_t i = 0; i < n; i++) {
    scanf("%I64d", &t);
    s1.insert(t);
    s2.insert(t);
    if (t != (t & x)) {
      m++;
      s2.insert(t & x);
    }
  }
  if (s1.size() != n) {
    printf("0");
    return 0;
  }
  for (int64_t i : s1) {
    if (s1.find(i & x) != s1.end() and (i & x) != i) {
      printf("1");
      return 0;
    }
  }
  if (s2.size() != m) {
    printf("2");
    return 0;
  }
  printf("-1");
  return 0;
}
