#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  std ::ios_base ::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    m[a[i]]++;
    if (m[a[i]] > 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (m[a[i] & x] > 0 && (a[i] & x) != a[i]) {
      cout << 1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if ((a[i] & x) != a[i]) m[a[i] & x]++;
  }
  for (auto it : m)
    if (it.second > 1) {
      cout << 2 << endl;
      return 0;
    }
  cout << -1 << endl;
}
