#include <bits/stdc++.h>
using namespace std;
void bug(string s = "lol", long long s1 = 1) { cout << s << " " << s1 << endl; }
int gcd(int f, int s) {
  if (s == 0)
    return f;
  else
    return gcd(s, f % s);
}
int const N = 600005;
long long const M = 998244353;
long double const ep = .000000000000000001;
int vis[N];
int arr[N];
int main() {
  int a, x;
  cin >> a >> x;
  for (int i = 0; i < a; i++) {
    int t;
    cin >> t;
    arr[i] = t;
    if (vis[t] == 1) {
      printf("0\n");
      return 0;
    }
    vis[t] = 1;
  }
  int mn = 3;
  for (int i = 0; i < a; i++) {
    vis[arr[i]] = 0;
    int t = (arr[i] & x);
    if (vis[t] == 1) {
      mn = min(1, mn);
    } else if (vis[t] == 2) {
      mn = min(2, mn);
    } else {
      vis[t] = 2;
    }
    vis[arr[i]] = 1;
  }
  if (mn == 3)
    printf("-1\n");
  else
    printf("%d\n", mn);
  return 0;
}
