#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238L;
void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int main() {
  init();
  int n, x;
  cin >> n >> x;
  int arr[n];
  set<int> s1, s2;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (s1.find(arr[i]) != s1.end())
      return cout << 0, 0;
    else
      s1.insert(arr[i]);
  }
  int ans = 3;
  for (int i = 0; i < n; i++) {
    int y = x & arr[i];
    if (y == arr[i] || s1.find(y) == s1.end())
      if (s2.find(y) != s2.end())
        ans = min(ans, 2);
      else
        s2.insert(y);
    else
      ans = 1;
  }
  if (ans == 3) ans = -1;
  cout << ans;
}
