#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100010], i, x, val;
  cin >> n >> x;
  int cnt[100010] = {0};
  int cnt2[100010] = {0};
  for (i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (i = 0; i < 100010; i++) {
    if (cnt[i] > 1) {
      cout << "0\n";
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    val = a[i] & x;
    if (cnt[val] > 0 && val != a[i]) {
      cout << "1\n";
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    val = a[i] & x;
    cnt2[val]++;
  }
  for (i = 0; i < 100010; i++) {
    if (cnt2[i] > 1) {
      cout << "2\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
