#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans *= a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
long long powm(long long a, long long b) {
  a %= MOD;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, a;
  cin >> n >> a;
  vector<int> A(n);
  map<int, int> freq;
  int maxi = 0;
  for (int &x : A) {
    cin >> x;
    freq[x]++;
    maxi = max(maxi, freq[x]);
  }
  if (maxi >= 2) {
    cout << 0 << "\n";
    return 0;
  }
  int cnt = 0;
  for (int &x : A) {
    int foo = (x & a);
    if (foo != x && freq[foo]) {
      cout << 1 << "\n";
      return 0;
    }
    if (foo == x) cnt++;
  }
  if (cnt == n) {
    cout << -1 << "\n";
    return 0;
  }
  freq.clear();
  for (int &x : A) {
    int foo = (x & a);
    freq[foo]++;
  }
  if ((int)freq.size() != n)
    cout << 2 << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
