#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  while (cin >> n >> x) {
    set<int> s;
    set<int> s1;
    int a[100001];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s.insert(a[i]);
    }
    if (s.size() < n)
      cout << 0 << endl;
    else {
      int t = 0, g = 0;
      for (int i = 0; i < n; i++) {
        int k = a[i] & x;
        if (k != a[i] && s.count(k)) {
          t = 1;
          break;
        } else if (k != a[i] && s1.count(k))
          t = 2;
        s1.insert(k);
      }
      if (t == 0)
        cout << -1 << endl;
      else if (t == 1)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    }
  }
  return 0;
}
