#include <bits/stdc++.h>
using namespace std;
multiset<int> q1, q2;
set<int> qq;
int tag1[100005];
int tag2[100005];
int main() {
  int n, x, number = 2;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    qq.insert(p);
    q1.insert(p);
    tag1[p]++;
    p = p & x;
    q2.insert(p);
    tag2[p]++;
  }
  if (qq.size() != q1.size()) {
    cout << 0 << endl;
    return 0;
  }
  number = -1;
  for (multiset<int>::iterator i = q1.begin(); i != q1.end(); i++) {
    if (tag1[*i] < tag2[*i]) number = 1;
  }
  if (number == -1)
    for (multiset<int>::iterator i = q2.begin(); i != q2.end(); i++) {
      if (tag2[*i] >= 2) number = 2;
    }
  cout << number << endl;
  return 0;
}
