#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, x;
  cin >> n >> x;
  map<long long, long long> kek;
  vector<long long> a(n);
  map<long long, long long> ans;
  long long answer = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (kek.find(a[i]) != kek.end()) {
      cout << 0;
      return 0;
    }
    kek[a[i]]++;
    if (ans.find(a[i]) != ans.end()) {
      answer = min(ans[a[i]], answer);
      ans[a[i]] = 0;
    } else
      ans.insert({a[i], 0});
    if ((a[i] & x) != a[i]) {
      if (ans.find(a[i] & x) != ans.end()) {
        answer = min(answer, 1 + ans[a[i] & x]);
      } else
        ans[a[i] & x] = 1;
    }
  }
  if (answer != 1e18)
    cout << answer;
  else
    cout << -1;
}
