#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], flag[maxn];
map<int, int> ma;
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    flag[a[i]]++;
    if (flag[a[i]] > 1) {
      printf("0\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    b[i] = a[i] & x;
    if (b[i] != a[i]) ma[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (ma[a[i]]) {
      if (ma[a[i]] != i) {
        printf("1\n");
        return 0;
      }
    }
  }
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= n; i++) {
    flag[b[i]]++;
    if (flag[b[i]] > 1) {
      printf("2\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
