#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, i, j, x, y, ans = 100, k;
  int a[1000001], b[1000001];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    cin >> j;
    if (a[j] == 1) {
      cout << 0;
      return;
    } else {
      a[j] = 1;
      k = j;
      j &= x;
      if (k != j) {
        if (b[j] == 1) {
          ans = 2;
        } else
          b[j] = 1;
      }
    }
  }
  for (i = 1; i <= 1000000; i++) {
    if (a[i] == 1 && b[i] == 1) {
      ans = 1;
    }
  }
  if (ans == 100)
    cout << -1;
  else
    cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
