#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, y, x;
  cin >> n >> y;
  map<int, vector<int> > pa;
  for (i = 0; i < n; i++) {
    cin >> x;
    pa[x].push_back(0);
    int cou = 0, prev = -1;
    while (x > 0) {
      prev = x;
      x = x & y;
      cou++;
      if (x == prev) break;
      pa[x].push_back(cou);
    }
  }
  int ans = INT_MAX;
  map<int, vector<int> >::iterator it;
  vector<int>::iterator it2;
  for (it = pa.begin(); it != pa.end(); it++) {
    sort(it->second.begin(), it->second.end());
    if (it->second.size() > 1) {
      if (ans > it->second[1] + it->second[0])
        ans = it->second[1] + it->second[0];
    }
  }
  if (ans == INT_MAX)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
