#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::max;
using std::min;
int n, m, A[100005], B[100005], cnt1[100005], cnt2[100005], Max, ans = 1e9;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]), B[i] = A[i] & m, cnt1[A[i]]++, cnt2[B[i]]++,
                        Max = max(Max, A[i]);
  for (int i = 1; i <= n; i++)
    if (cnt1[A[i]] > 1) return puts("0"), 0;
  for (int i = 1; i <= n; i++)
    if (cnt1[B[i]] - (A[i] == B[i])) return puts("1"), 0;
  for (int i = 1; i <= n; i++)
    if (cnt2[B[i]] > 1) return puts("2"), 0;
  puts("-1");
  return 0;
}
