#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m;
map<int, bool> ma, mb;
int a[maxn], b[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (ma[a[i]] == true) {
      printf("0\n");
      return 0;
    }
    ma[a[i]] = true;
  }
  int ans = 3;
  for (int i = 1; i <= n; i++) {
    b[i] = (a[i] & m);
    if (ma[b[i]] == true && a[i] != b[i]) {
      ans = min(ans, 1);
      break;
    }
    if (mb[b[i]] == true) {
      ans = min(ans, 2);
    }
    mb[b[i]] = true;
  }
  if (ans == 3) ans = -1;
  printf("%d\n", ans);
  return 0;
}
