#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010], v[100010];
int main() {
  int n, x, ans = 999999;
  scanf("%d%d", &n, &x);
  memset(v, -1, sizeof(v));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i] & x;
    if (v[a[i]] != -1) {
      if (ans > v[a[i]]) ans = v[a[i]];
    } else if (v[b[i]] != -1) {
      if (ans > v[b[i]] + 1) ans = v[b[i]] + 1;
    }
    if (v[a[i]] == 1 || v[a[i]] == -1) v[a[i]] = 0;
    if (v[b[i]] == -1) v[b[i]] = 1;
  }
  if (ans == 999999)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
