#include <bits/stdc++.h>
using namespace std;
int n, x, a[100001];
bool dx[100001];
bool dx1[100001];
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (dx[a[i]]) {
      cout << 0;
      return 0;
    }
    dx[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    int p = a[i] & x;
    if (dx[p] && p != a[i]) {
      cout << 1;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    int p = a[i] & x;
    if (dx1[p]) {
      cout << 2;
      return 0;
    }
    dx1[p] = true;
  }
  cout << -1;
}
