#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const long long M = 1e18;
map<long long, bool> mm;
map<long long, bool> m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, x, a, t = 5;
  cin >> n >> x;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    if (m[a]) return cout << 0, 0;
    m[a] = true;
    if (mm[a] || m[a & x] && (a & x) != a) t = 1;
    if (mm[a & x]) t = min(t, 2);
    mm[a & x] = true;
  }
  if (t == 5)
    cout << -1;
  else
    cout << t;
}
