#include <bits/stdc++.h>
using namespace std;
int a[100050], vis[100050], b[100050];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int flag = 0;
    memset(vis, 0, sizeof(vis));
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      vis[a[i]]++;
      if (vis[a[i]] >= 2) flag = 1;
    }
    if (flag) {
      printf("0\n");
      continue;
    }
    flag = -1;
    for (int i = 1; i <= n; i++) {
      int t = a[i] & m;
      if (t != a[i]) b[t]++;
      if (b[t] >= 2) flag = 2;
    }
    for (int i = 1; i <= 100000; i++) {
      if (vis[i] != 0 && b[i] != 0) {
        flag = 1;
      }
    }
    printf("%d\n", flag);
  }
}
