#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int cnt[MAXN];
int a[MAXN];
int n;
int x;
bool vis[MAXN];
int main() {
  memset(cnt, 0, sizeof(cnt));
  memset(vis, false, sizeof(vis));
  cin >> n >> x;
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    if (cnt[a[i]] >= 2) flag = true;
  }
  if (flag) {
    cout << 0 << endl;
    return 0;
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    int temp = a[i] & x;
    if (vis[temp]) ans = 2;
    vis[temp] = true;
  }
  for (int i = 1; i <= n; i++) {
    int temp = a[i] & x;
    if (cnt[temp] > 0) {
      if (temp != a[i]) {
        ans = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
