#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010], R[100010], ans[100010];
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (R[a[i]]) return cout << 0, 0;
    R[a[i]] = i;
    b[i] = a[i] & x;
  }
  for (int i = 1; i <= n; i++) {
    if (R[b[i]] > 0 && R[b[i]] != i) return cout << 1, 0;
    ans[b[i]]++;
  }
  for (int i = 0; i < 100010; i++) {
    if (ans[i] > 1) return cout << 2, 0;
  }
  return cout << -1, 0;
}
