#include <bits/stdc++.h>
const int mo = 1000000007;
const int inf = 0x3f3f3f3f;
double pi = 3.14159265358979323846;
double e = 2.71828182845904523536;
using namespace std;
map<long long, long long> m, m2;
int main() {
  int a[100005];
  int n, x;
  int cnt = 0;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    m[a[i]]++;
    if (m[a[i]] >= 2) cnt = 1;
  }
  if (cnt) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 1; i <= n; i++) {
      if ((a[i] & x) == a[i]) continue;
      m2[a[i] & x]++;
      if (m[a[i] & x]) {
        cout << 1 << endl;
        return 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (m2[a[i] & x] >= 2) {
        cout << 2 << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
