#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int n, x;
    cin >> n >> x;
    long long int arr[n + 1], brr[n + 1];
    map<long long int, long long int> ma, mb;
    for (long long int i = 1; i <= n; i++) {
      cin >> arr[i];
      ma[arr[i]]++;
      brr[i] = arr[i] & x;
      mb[brr[i]]++;
    }
    for (auto i : ma) {
      if (i.second >= 2) {
        cout << 0 << '\n';
        return 0;
      }
    }
    long long int mini = 1000000007;
    for (long long int i = 1; i <= n; i++) {
      if (brr[i] != arr[i]) {
        if (ma[brr[i]] >= 1) {
          cout << 1 << '\n';
          return 0;
        }
        if (mb[brr[i]] >= 2) {
          mini = 2;
        }
      }
    }
    if (mini == 2) {
      cout << 2;
    } else {
      cout << -1;
    }
  }
  return 0;
}
