#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, bool> Sau, Truoc;
int a[N], n, x, res = -1;
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (Truoc[a[i]] == true)
      res = 1;
    else
      Truoc[a[i]] = true;
  }
  if (res == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int t = (x & a[i]);
    if (t == a[i]) {
      if (Sau[t] == true) {
        res = 1;
        break;
      }
    } else {
      if (Truoc[t] == true) {
        res = 1;
        break;
      } else if (Sau[t] == true)
        res = 2;
    }
    Sau[t] = true;
  }
  cout << res;
  return 0;
}
