#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  while (cin >> n >> x) {
    int a[100011];
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);
    map<int, bool> mp, lol;
    for (int i = 0; i < n; ++i) {
      if (mp[a[i]]) {
        cout << "0" << '\n';
        return 0;
      }
      mp[a[i]] = 1;
    }
    bool f = 0;
    for (int i = n - 1; i >= 0; --i) {
      int num = a[i] & x;
      if (lol[num]) f = 1;
      if (num != a[i]) lol[num] = 1;
      if (num != a[i] and mp[num]) {
        cout << "1" << '\n';
        return 0;
      }
    }
    if (f)
      cout << "2" << '\n';
    else
      cout << "-1" << '\n';
  }
}
