#include <bits/stdc++.h>
using namespace std;
int bsearch(int x, int l, int r, int arr[]) {
  if (r >= l) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == x) return 1;
    if (arr[mid] > x) return bsearch(x, l, mid - 1, arr);
    return bsearch(x, mid + 1, r, arr);
  }
  return -1;
}
int main() {
  int n, x, flag = 0;
  cin >> n >> x;
  int arr[n], b[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  for (int i = 1; i < n; i++) {
    if (arr[i] == arr[i - 1]) flag = 1;
  }
  if (flag != 1) {
    for (int i = 0; i < n; i++) {
      b[i] = arr[i] & x;
      if (bsearch(b[i], 0, i - 1, arr) == 1) {
        flag = 2;
        break;
      }
    }
  }
  sort(b, b + n);
  for (int i = 1; i < n; i++) {
    if (b[i] == b[i - 1] && flag != 1 && flag != 2) flag = 3;
  }
  cout << flag - 1;
  return 0;
}
