#include <bits/stdc++.h>
using namespace std;
int a[100007], j[100007], j2[100007];
int main() {
  int n, x;
  memset(j, 0, sizeof(j));
  memset(j2, 0, sizeof(j2));
  cin >> n >> x;
  map<int, int> ss;
  int f = 3;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    j[a[i]]++;
    if (j[a[i]] >= 2) f = 0;
  }
  for (int i = 1; i <= n; i++) {
    int m = a[i];
    a[i] = a[i] & x;
    if (j[a[i]] >= 1 && (a[i] != m)) f = min(1, f);
    if (j2[a[i]] >= 1) f = min(2, f);
    j2[a[i]]++;
  }
  if (f != 3)
    cout << f << endl;
  else
    cout << -1 << endl;
}
