#include <bits/stdc++.h>
using namespace std;
vector<int> fre;
int main() {
  int n, x;
  cin >> n >> x;
  int a[n];
  map<int, int> fre;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    fre[a[i]] += 1;
  }
  if (fre.size() != n) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != (a[i] & x) && fre.count((a[i] & x))) {
      cout << 1 << endl;
      return 0;
    }
  }
  fre.clear();
  for (int i = 0; i < n; i++) fre[a[i] & x]++;
  if (fre.size() != n)
    cout << 2 << endl;
  else
    cout << -1 << endl;
  return 0;
}
