#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1e6 + 1;
const int M = 1e3;
int a[N];
int cnt[N];
bool was[N];
vector<int> Or;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  bool tw = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (was[a[i]]) {
      tw = 1;
    }
    was[a[i]] = 1;
    Or.push_back(a[i] & m);
  }
  if (tw) {
    cout << 0;
    return 0;
  }
  set<int> s;
  for (int i = 0; i < n; ++i) {
    was[a[i + 1]] = 0;
    if (was[Or[i]]) {
      cout << 1;
      return 0;
    }
    was[a[i + 1]] = 1;
    s.insert(Or[i]);
  }
  if ((int)s.size() != n) {
    cout << 2;
  } else {
    cout << -1;
  }
}
