#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j = 0, k = 0;
  cin >> n >> k;
  long long x;
  long long a[n + 3];
  for (i = 0; i < n; ++i) {
    cin >> a[i];
  }
  unordered_map<long long, long long> m1;
  for (i = 0; i < n; ++i) m1[a[i]]++;
  for (i = 0; i < n; ++i) {
    if (m1[a[i]] > 1) {
      cout << 0;
      return 0;
    }
  }
  for (i = 0; i < n; ++i) {
    if ((a[i] & k) != a[i] && m1[(a[i] & k)]) {
      cout << 1;
      return 0;
    }
    a[i] = (a[i] & k);
  }
  m1.clear();
  for (i = 0; i < n; ++i) m1[a[i]]++;
  for (i = 0; i < n; ++i) {
    if (m1[a[i]] > 1) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
}
