#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k, x;
int a[maxn], cnt[maxn];
int main() {
  while (cin >> n >> x) {
    memset(cnt, 0, sizeof(cnt));
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      cnt[a[i]]++;
      if (cnt[a[i]] >= 2) flag = 1;
    }
    if (flag)
      cout << 0 << endl;
    else {
      for (int i = 0; i < n; i++) {
        if ((a[i] & x) == a[i]) continue;
        if (cnt[a[i] & x]) {
          flag = 1;
          break;
        }
      }
      if (flag)
        cout << 1 << endl;
      else {
        memset(cnt, 0, sizeof(cnt));
        for (int i = 0; i < n; i++) {
          cnt[a[i] & x]++;
          if (cnt[a[i] & x] >= 2) {
            flag = 1;
            break;
          }
        }
        if (flag)
          cout << 2 << endl;
        else
          cout << -1 << endl;
      }
    }
  }
  return 0;
}
