#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x;
  int ara[100001], given[n], f = 0;
  memset(ara, 0, sizeof(ara));
  for (int i = 0; i < n; i++) {
    cin >> given[i];
    if (ara[given[i]] == 0) {
      ara[given[i]] = 1;
    } else {
      f = 1;
    }
  }
  if (f == 1) {
    cout << 0 << endl;
    return 0;
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    int t = given[i] & x;
    if (ara[t] == 1 || ara[t] == 2) {
      if (t == given[i]) {
        continue;
      }
      k = ara[t];
      if (k == 1) {
        break;
      }
    }
    ara[t] = 2;
  }
  if (k > 0) {
    cout << k << endl;
  } else {
    cout << -1 << endl;
  }
}
