#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> used(MAXN);
  vector<int> ch(MAXN);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++used[a[i]];
    if (used[a[i]] > 1) {
      cout << 0;
      exit(0);
    }
  }
  int flag = -1;
  for (int i = 0; i < n; ++i) {
    int kek = (a[i] & x);
    ++ch[kek];
    if (ch[kek] > 1) flag = 2;
    if ((kek == a[i] && used[kek] > 1) || (kek != a[i] && used[kek] >= 1)) {
      cout << "1";
      exit(0);
    }
  }
  cout << flag;
  return 0;
}
