#include <bits/stdc++.h>
using namespace std;
long long int n, x;
vector<long long int> arr;
map<long long int, long long int> s;
vector<long long int> res;
map<long long int, long long int> r;
int main() {
  cin >> n >> x;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    arr.push_back(a);
    s[a]++;
  }
  for (auto it : s) {
    if (it.second >= 2) {
      cout << 0;
      return 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (s[arr[i] & x] == 1 and arr[i] != (arr[i] & x)) {
      cout << 1;
      return 0;
    }
    r[(arr[i] & x)]++;
  }
  for (auto it : r) {
    if (it.second >= 2) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
