#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
int main() {
  int n, first;
  cin >> n >> first;
  vector<int> a(n);
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    if (mp[a[i]] > 1) {
      cout << 0;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    int k = a[i] & first;
    if (binary_search(a.begin(), a.end(), k)) {
      if ((lower_bound(a.begin(), a.end(), k) - a.begin()) != i) {
        cout << 1;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) a[i] = a[i] & first;
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
}
