#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  bool f;
  cin >> n >> x;
  int ar[n];
  map<int, int> a, b;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    a[ar[i]] = i + 1;
  }
  if (a.size() < n)
    cout << "0\n";
  else {
    f = 0;
    for (int i = 0; i < n; i++) {
      if (a[ar[i] & x] > 0 && a[ar[i] & x] != i + 1) f = 1;
      b[ar[i] & x] = 1;
    }
    if (f)
      cout << "1\n";
    else if (b.size() < n)
      cout << "2\n";
    else
      cout << "-1\n";
  }
  return 0;
}
