#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, x, a[110000], s[110000], ans = 66666;
inline void read(int& sum) {
  char ch = getchar();
  sum = 0;
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') sum = sum * 10 + ch - '0', ch = getchar();
}
inline int mymin(const int& x, const int& y) { return x < y ? x : y; }
int main() {
  read(n), read(x);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    if (s[a[i]] != 0) {
      printf("0\n");
      return 0;
    }
    s[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (s[a[i] & x] != 0 && (a[i] & x) != a[i]) ans = mymin(ans, s[a[i] & x]);
    if (s[a[i] & x] == 0) s[a[i] & x] = 2;
  }
  if (ans != 66666)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
