#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;
int n, x;
long long second, s2;
map<int, int> mp;
int a[N], b[N];
bool ok = 0;
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (mp[a[i]] == 1) ok = 1;
    mp[a[i]]++;
  }
  if (ok == 1) {
    cout << 0 << "\n";
    exit(0);
  }
  for (int i = 1; i <= n; i++) {
    mp[a[i]]--;
    if (mp[a[i] & x] != 0) ok = 1;
    mp[a[i]]++;
  }
  if (ok == 1) {
    cout << 1 << "\n";
    exit(0);
  }
  mp.clear();
  for (int i = 1; i <= n; i++) {
    a[i] = (a[i] & x);
    if (mp[a[i]] == 1) ok = 1;
    mp[a[i]]++;
  }
  if (ok == 1) {
    cout << 2 << "\n";
    exit(0);
  }
  cout << -1 << "\n";
  exit(0);
}
