#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline istream& operator>>(istream& is, vector<T>& v) {
  for (auto& e : v) {
    is >> e;
  }
  return is;
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
  for (const auto& e : v) {
    os << e << " ";
  }
  os << "\n";
  return os;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, x, answer = 3;
  cin >> n >> x;
  vector<int> a(n);
  cin >> a;
  vector<int> f(100001, 0), s(100001, 0);
  for (int i = 0; i < static_cast<int>(n); ++i) {
    ++f[a[i]];
    if ((a[i] & x) != a[i]) {
      ++s[a[i] & x];
    }
  }
  for (int i = 0; i < static_cast<int>(100001); ++i) {
    if (f[i] > 1) {
      answer = 0;
    } else if (answer > 1 && f[i] && s[i]) {
      answer = 1;
    } else if (answer > 2 && s[i] > 1) {
      answer = 2;
    }
  }
  if (answer == 3) {
    cout << -1;
  } else {
    cout << answer;
  }
  return 0;
}
