#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, f[100005] = {0}, s[100005] = {0}, n, a[100005];
  int x, ans;
  cin >> n >> x;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    f[a[i]]++;
    if ((a[i] & x) == a[i]) continue;
    s[a[i] & x]++;
  }
  for (i = 0; i <= 100000; i++) {
    if (f[i] >= 2) {
      printf("0");
      return 0;
    }
  }
  for (i = 0; i <= 100000; i++) {
    if (f[i] > 0 && s[i] > 0) {
      printf("1");
      return 0;
    }
  }
  for (i = 0; i <= 100000; i++) {
    if (s[i] >= 2) {
      printf("2");
      return 0;
    }
  }
  printf("-1");
  return 0;
}
