#include <bits/stdc++.h>
int a[100006];
int vis[100006];
int visyu[100006];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    vis[a[i]]++;
    if (vis[a[i]] == 2) {
      printf("0\n");
      return 0;
    }
  }
  int mans = -1;
  for (int i = 1; i <= n; i++) {
    visyu[a[i] & x]++;
    if (visyu[a[i] & x] && vis[a[i] & x] && ((a[i] & x) != a[i])) {
      printf("1\n");
      return 0;
    } else if (visyu[a[i] & x] == 2) {
      mans = 2;
    }
  }
  printf("%d\n", mans);
}
