#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  map<int, int> cnt;
  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
    cnt[i]++;
    if (cnt[i] == 2) {
      cout << 0;
      return 0;
    }
  }
  for (auto &i : a) {
    cnt[i]--;
    if (cnt[i & x] == 1) {
      cout << 1;
      return 0;
    } else
      cnt[i]++;
  }
  cnt.clear();
  for (auto &i : a) {
    cnt[i & x]++;
    if (cnt[i & x] == 2) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
