#include <bits/stdc++.h>
using namespace std;
int n, m, x, sum, ans = 99999;
int a[100005], b[100005];
bool vis[100005][5], vis1[100005], flag = 0;
int main() {
  memset(vis1, 0, sizeof(vis1));
  memset(vis, 0, sizeof(vis));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (vis1[a[i]] == 0) {
      vis1[a[i]] = 1;
    } else {
      ans = 0;
      flag = 1;
    }
    if (!flag) {
      b[i] = (a[i] & m);
      if (a[i] == b[i]) {
        if (vis[a[i]][0] == 0 && vis[a[i]][1] == 0) {
          vis[a[i]][0] = 1;
        } else {
          if (vis[a[i]][0] == 1) {
            sum = 0;
          }
          if (vis[a[i]][1] == 1) {
            sum = 1;
          }
          vis[a[i]][0] = 1;
          ans = min(ans, sum);
        }
      } else {
        if (vis[a[i]][0] == 0 && vis[a[i]][1] == 0 && vis[b[i]][0] == 0 &&
            vis[b[i]][1] == 0) {
          vis[a[i]][0] = 1;
          vis[b[i]][1] = 1;
        } else {
          if (vis[a[i]][0] == 1) {
            sum = 0;
          } else if (vis[a[i]][1] == 1) {
            sum = 1;
          } else if (vis[b[i]][0] == 1) {
            sum = 1;
          } else if (vis[b[i]][1] == 1) {
            sum = 2;
          }
          ans = min(ans, sum);
          vis[a[i]][0] = 1;
          vis[b[i]][1] = 1;
        }
      }
    }
  }
  if (ans != 99999)
    printf("%d", ans);
  else
    printf("-1");
  return 0;
}
