#include <bits/stdc++.h>
using namespace std;
int visited[100001] = {0};
int main() {
  int n, x;
  cin >> n >> x;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    visited[arr[i]]++;
    if (visited[arr[i]] == 2) {
      cout << 0;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int temp = arr[i] & x;
    visited[arr[i]]--;
    visited[temp]++;
    if (visited[temp] == 2) {
      cout << 1;
      return 0;
    }
    visited[arr[i]]++;
    visited[temp]--;
  }
  for (int i = 0; i < n; i++) {
    visited[arr[i]]--;
    arr[i] = arr[i] & x;
    visited[arr[i]]++;
    if (visited[arr[i]] == 2) {
      cout << 2;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
