#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  long long m, n, k;
  while (tt--) {
    cin >> n >> k;
    vector<int> vec(n);
    for (long long i = 0; i < n; i++) {
      cin >> vec[i];
    };
    sort(vec.begin(), vec.end());
    set<int> s;
    for (long long i = 0; i < n; i++) {
      s.insert(vec[i]);
    }
    if (s.size() != n) {
      cout << 0 << endl;
    } else {
      for (long long i = 0; i < n; i++) {
        int no = vec[i] & k;
        if (no == vec[i])
          ;
        if (no == vec[i] and
            binary_search(vec.begin() + i + 1, vec.end(), no)) {
          cout << 1 << endl;
          return 0;
        } else if (no != vec[i] and binary_search(vec.begin(), vec.end(), no)) {
          cout << 1 << endl;
          return 0;
        }
      }
      s.clear();
      for (long long i = 0; i < n; i++) {
        s.insert(vec[i] & k);
      }
      if (s.size() != n)
        cout << 2 << endl;
      else
        cout << -1 << endl;
    }
  }
}
