#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
int main() {
  long long n, x;
  cin >> n >> x;
  long long a[n];
  map<long long, long long> ma;
  for (int i = 0; i < n; i++) cin >> a[i], ma[a[i]]++;
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) mp[a[i] & x]++;
  for (auto e : ma)
    if (e.second >= 2) {
      cout << 0 << endl;
      return 0;
    }
  long long ans = 100000000000;
  for (auto e : ma) {
    if (e.second > 0) {
      if (mp[e.first & x] >= 1) {
        if (e.second == 1 && (e.first & x) == e.first)
          continue;
        else {
          if (ma[e.first & x] == 1) {
            ans = min(ans, 1LL);
          } else if (mp[e.first & x] >= 2) {
            ans = min(ans, 2LL);
          }
        }
      }
    }
  }
  if (ans == 100000000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
