#include <bits/stdc++.h>
using namespace std;
int count(vector<int> &a, int x) {
  set<int> sa, sax;
  int ans = 3;
  for (auto &k : a) {
    if (sa.count(k))
      ans = 0;
    else if (sa.count(k & x) || sax.count(k))
      ans = min(ans, 1);
    else if (sax.count(k & x))
      ans = min(ans, 2);
    sa.insert(k);
    sax.insert(k & x);
  }
  return (ans == 3 ? -1 : ans);
}
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << count(a, x) << endl;
  return 0;
}
