#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int ar[n];
  bool ck = 0;
  set<int> st;
  unordered_map<int, bool> mp;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    st.insert(ar[i]);
  }
  if ((int)st.size() != n) {
    cout << "0\n";
    return;
  }
  int ans = 10;
  for (int i = 0; i < n; i++) {
    int nw = ar[i] & k;
    bool ck1 = 0;
    if (nw != ar[i]) {
      if (mp[nw] == 0)
        mp[nw] = true;
      else {
        ans = min(2, ans);
        continue;
      }
      ck1 = 1;
    }
    int ss = st.size();
    st.insert(nw);
    if ((int)st.size() == ss && ck1) {
      cout << "1\n";
      return;
    }
  }
  if (ans == 10)
    cout << "-1\n";
  else
    cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(NULL);
  solve();
  return 0;
}
