#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  int f = 0;
  cin >> n >> x;
  int a[n], b[100001] = {0}, c[100001] = {0}, ans;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
    if (b[a[i]] == 2) f = 1;
  }
  if (f == 1)
    cout << 0;
  else {
    for (int i = 0; i < n; i++) {
      int s = (48948 & x);
      int p = (34596 & x);
      if (b[a[i] & x] > 0 && a[i] != (a[i] & x)) {
        f = 1;
        ans = 1;
        break;
      } else if (c[a[i] & x] > 0) {
        f = 1;
        ans = 2;
      }
      c[(a[i] & x)]++;
    }
    if (f == 1)
      cout << ans;
    else
      cout << "-1";
  }
}
