#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], f[100005], x;
map<int, int> m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[(a[i] & x)]++;
    f[a[i]]++;
    if (f[a[i]] > 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int k = (a[i] & x);
    if (k == a[i]) {
      if (f[k] >= 2) {
        cout << 1 << endl;
        return 0;
      }
    } else {
      if (f[k]) {
        cout << 1 << endl;
        return 0;
      }
    }
  }
  for (auto it = m.begin(); it != m.end(); it++) {
    int k = it->second;
    if (k >= 2) {
      cout << 2 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
