#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
const long long int N = 100005;
const long long int MAX = 1e6 + 3;
long long int modPow(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long int nCr(long long int n, long long int k) {
  long long int res = 1;
  if (n < k) return 0;
  if (k > n - k) k = n - k;
  for (long long int i = 0; i < k; ++i) {
    res = (res * (n - i)) % mod;
    res = (res * modPow(i + 1, mod - 2)) % mod;
  }
  return res;
}
set<long long int> s;
void Sieve() {
  bool prime[1000009];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= 1000006; p++)
    if (prime[p] == true)
      for (long long int i = p * 2; i <= 1000006; i += p) prime[i] = false;
  for (long long int i = 2; i < 1000006; i++)
    if (prime[i] == true) s.insert(i);
}
long long int factorial(long long int n) {
  if (n == 1) return 1;
  return (n * factorial(n - 1)) % mod;
}
long long int catalan(long long int n) {
  return (nCr(2 * n, n) * modPow(n + 1, mod - 2)) % mod;
}
int main() {
  long long int n, x;
  cin >> n >> x;
  set<int> s;
  long long int a[n], b[n], h[100001] = {0}, hi[100001] = {0};
  for (int i = 0; i < n; i++) cin >> a[i], h[a[i]]++, s.insert(a[i]);
  for (int i = 0; i < 100001; i++)
    if (h[i] > 1) return cout << 0, 0;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    b[i] = a[i] & x;
    hi[b[i]]++;
    if ((s.count(b[i]) == 1) && a[i] != (a[i] & x)) return cout << 1, 0;
  }
  for (int i = 0; i < 100001; i++)
    if (hi[i] > 1) return cout << 2, 0;
  cout << -1 << "\n";
}
