#include <bits/stdc++.h>
using namespace std;
bool cek[100000];
int cnt[100000];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v;
  long long input;
  memset(cek, 0, sizeof(cek));
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> input;
    v.push_back(input);
    if (cek[input] == 0) {
      cek[input] = 1;
    } else
      flag = 1;
  }
  if (flag)
    cout << 0 << endl;
  else {
    long long ans = 999999;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < v.size(); i++) {
      long long temp = 999999;
      if ((v[i] & k) != v[i] && cek[v[i] & k] == 0) {
        if (cnt[v[i] & k] > 0) {
          temp = 2;
        }
      }
      if ((v[i] & k) != v[i] && cek[(v[i] & k)] == 1) {
        temp = 1;
      }
      if ((v[i] & k) != v[i] && cek[(v[i] & k)] == 0) {
        cnt[(v[i] & k)]++;
      }
      ans = min(temp, ans);
    }
    if (ans == 999999)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
