#include <bits/stdc++.h>
using namespace std;
int a[100001] = {0}, b[100001] = {0}, n, x, y;
int main() {
  cin >> n >> x;
  int answer = -1;
  while (n--) {
    cin >> y;
    if (a[y]) answer = 0;
    if (answer && (a[x & y] || b[y])) answer = 1;
    if (answer && answer != 1 && b[x & y]) answer = 2;
    a[y] = b[x & y] = 1;
  }
  cout << answer << endl;
  return 0;
}
