#include <bits/stdc++.h>
using namespace std;
int a[100005];
int num[100005];
int vis[100005];
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    num[a[i]]++;
    if (num[a[i]] >= 2) {
      cout << 0 << "\n";
      return 0;
    }
    vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    int b = a[i];
    b = b & k;
    if (vis[b] && b != a[i]) {
      cout << "1\n";
      return 0;
    }
  }
  memset(vis, 0, sizeof(vis));
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= n; i++) {
    int b = a[i];
    b = b & k;
    num[b]++;
    if (num[b] >= 2) {
      cout << 2 << "\n";
      return 0;
    }
  }
  cout << "-1\n";
}
