#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, x;
  cin >> n >> x;
  vector<long long> vec(n);
  for (long long i = 0; i < n; i++) cin >> vec[i];
  vector<long long> anded(n);
  for (long long i = 0; i < n; i++) anded[i] = vec[i] & x;
  multiset<long long> s;
  for (long long i = 0; i < n; i++) {
    s.insert(vec[i]);
    if (s.count(vec[i]) > 1) {
      cout << 0;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    if ((s.count(anded[i]) == 1 && vec[i] != anded[i]) ||
        (s.count(anded[i]) > 1)) {
      cout << 1;
      return 0;
    }
  }
  s.clear();
  for (long long i = 0; i < n; i++) {
    s.insert(anded[i]);
    if (s.count(anded[i]) > 1) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
