#include <bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[100005];
map<int, int> dp;
int main() {
  int ok = 0;
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    if (cnt[a[i]] == 2) {
      ok = 1;
    }
  }
  if (ok) {
    printf("0\n");
    return 0;
  }
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    cnt[a[i] & x]++;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == (a[i] & x) && cnt[a[i]] > 1) {
      printf("1\n");
      return 0;
    }
    if (a[i] != (a[i] & x) && cnt[a[i]] > 0) {
      printf("1\n");
      return 0;
    }
  }
  for (int i = 0; i <= 100000; i++) {
    if (cnt[i] > 1) {
      printf("2\n");
      return 0;
    }
  }
  printf("-1\n");
}
