#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
bool mk1[100009], mk2[100001];
void BACKSLASH() {
  int t;
  int n, x, ans = 1e9;
  cin >> n >> x;
  int a;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (mk1[a]) {
      ans = 0;
    } else if (mk1[a & x] || mk2[a]) {
      ans = min(ans, 1);
    } else if (mk2[a & x]) {
      ans = min(ans, 2);
    }
    mk1[a] = 1;
    mk2[a & x] = 1;
  }
  if (ans >= 1e9) {
    ans = -1;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  BACKSLASH();
  return 0;
}
