#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const double PI = acos(-1);
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
long long n, x;
long long a[100010];
long long vis[500010];
long long vis2[500010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  int flag = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (vis[a[i]] == 0)
      vis[a[i]] = 1;
    else
      flag = 1;
  }
  if (flag == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    long long tmp = a[i] & x;
    if (vis[tmp] == 1 && tmp != a[i]) {
      flag = 1;
      break;
    }
    if (tmp != a[i]) vis2[tmp]++;
  }
  if (flag == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < 500005; i++) {
    if (vis2[i] >= 2) {
      cout << 2 << endl;
      return 0;
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
    return 0;
  }
}
