#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, typename TT>
inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {
  return os << t.first << " " << t.second;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &t) {
  for (auto i : t) os << i << " ";
  return os;
}
template <typename T>
inline istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &is, pair<T1, T2> &t) {
  is >> t.first >> t.second;
  return is;
}
const long long mod = 1e9 + 7;
void solve() {
  long long n, x;
  cin >> n >> x;
  vector<long long> v(n);
  cin >> v;
  vector<long long> b(n);
  map<long long, long long> m1, m2;
  long long ans = 1e18;
  for (int i = 0; i < n; i++) {
    if (m1.find(v[i]) != m1.end()) {
      cout << 0 << '\n';
      return;
    }
    b[i] = (v[i] & x);
    if (m2.find(v[i]) != m2.end()) ans = min(ans, 1ll);
    if (m1.find(b[i]) != m1.end()) ans = min(ans, 1ll);
    if (m2.find(b[i]) != m2.end()) ans = min(ans, 2ll);
    m1[v[i]] = i;
    m2[b[i]] = i;
  }
  cout << (ans >= 1e18 ? -1 : ans) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
