#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int n, x;
  cin >> n >> x;
  vector<long long int> arr;
  long long int a[100003];
  for (long long int i = 0; i < n; i++) {
    long long int y;
    cin >> y;
    arr.push_back(y);
    a[y]++;
  }
  sort(arr.begin(), arr.end());
  for (long long int i = 0; i < n - 1; i++) {
    if (arr[i] == arr[i + 1]) {
      cout << "0";
      return 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    long long int k = arr[i] & x;
    if (a[k] > 0 && k != arr[i]) {
      cout << "1";
      return 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    arr[i] = arr[i] & x;
  }
  sort(arr.begin(), arr.end());
  for (long long int i = 0; i < n - 1; i++) {
    if (arr[i] == arr[i + 1]) {
      cout << "2";
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
