#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, x;
  cin >> n >> x;
  long int arr[n];
  for (long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long int arr_save[100000];
  for (long int i = 0; i < 100000; i++) {
    arr_save[i] = 0;
  }
  long int flag = 1;
  for (long int i = 0; i < n; i++) {
    arr_save[arr[i] - 1] += 1;
    if (arr_save[arr[i] - 1] == 2) {
      cout << 0;
      flag = 0;
      break;
    }
  }
  if (flag == 1) {
    long int fl = 0;
    long int arr_2[100001];
    for (long int i = 0; i < 100001; i++) {
      arr_2[i] = 0;
    }
    for (long int i = 0; i < n; i++) {
      long int val;
      val = arr[i] & x;
      if (val == arr[i]) {
        arr_2[val] += 1;
      } else {
        if (arr_save[val - 1] != 0 && val != 0) {
          cout << 1;
          fl = 1;
          break;
        } else {
          arr_2[val] += 1;
        }
      }
    }
    if (fl == 0) {
      long int max1 = 0;
      for (long int i = 0; i < 100001; i++) {
        if (arr_2[i] > max1) {
          max1 = arr_2[i];
        }
      }
      if (max1 == 1) {
        cout << -1;
      } else {
        cout << 2;
      }
    }
  }
}
