#include <bits/stdc++.h>
using namespace std;
int n, x;
int A[100010], B[100010] = {0}, C[100010] = {0};
int main() {
  cin >> n >> x;
  bool judge = false;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    B[A[i]]++;
    if (B[A[i]] >= 2) judge = true;
  }
  if (judge)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) {
      int t = A[i] & x;
      if ((t != A[i] && B[t] >= 1)) {
        cout << 1 << endl;
        return 0;
      } else {
        C[t]++;
      }
    }
    for (int i = 0; i <= 100000; i++) {
      if (C[i] >= 2) {
        cout << 2 << endl;
        return 0;
      }
    }
    cout << -1 << endl;
  }
}
