#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  set<long long int> s, m;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    s.insert(x);
  }
  if (s.size() < n) {
    cout << "0\n";
    return 0;
  }
  for (auto &y : s) {
    if ((y & k) != y and s.find((y & k)) != s.end()) {
      cout << "1\n";
      return 0;
    }
  }
  for (auto &y : s) {
    if (m.find(y & k) != m.end()) {
      cout << "2\n";
      return 0;
    } else
      m.insert(y & k);
  }
  cout << "-1\n";
}
