There is an array with n elements a_1, a_2, ..., a_{n} and the number x.

In one operation you can select some i (1 ≤ i ≤ n) and replace element a_{i} with a_{i} & x, where & denotes the bitwise and operation.

You want the array to have at least two equal elements after applying some operations (possibly, none). In other words, there should be at least two distinct indices i ≠ j such that a_{i} = a_{j}. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.


-----Input-----

The first line contains integers n and x (2 ≤ n ≤ 100 000, 1 ≤ x ≤ 100 000), number of elements in the array and the number to and with.

The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 100 000), the elements of the array.


-----Output-----

Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.


-----Examples-----
Input
4 3
1 2 3 7

Output
1

Input
2 228
1 1

Output
0

Input
3 7
1 2 3

Output
-1



-----Note-----

In the first example one can apply the operation to the last element of the array. That replaces 7 with 3, so we achieve the goal in one move.

In the second example the array already has two equal elements.

In the third example applying the operation won't change the array at all, so it is impossible to make some pair of elements equal.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
(n, x) = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
nums1 = nums[:]
nums = set(nums)
if len(set(nums)) < n:
	print(0)
	exit(0)
for i in range(len(nums)):
	if nums1[i] & x in nums and nums1[i] != nums1[i] & x:
		print(1)
		exit(0)
for i in range(len(nums)):
	nums1[i] = nums1[i] & x
if len(set(nums1)) < n:
	print(2)
	exit(0)
print(-1)


a = lambda : map(int, input().split())
(n, x) = a()
(c, e) = (set(a()), set())
result = (2, 0)[len(c) < n]
for i in c:
	if result and i & x != i and (i & x in c):
		result = 1
	e.add(i & x)
print((-1, result)[len(e) < n])


(n, x) = [int(x) for x in input().split()]
li = set([*map(int, input().split())])
t = len(li)
t1 = len(li)
t2 = len(li)
t3 = len(li)
if len(li) < n:
	print(0)
	quit()
for i in li:
	if i & x != i and i & x in li:
		print(1)
		quit()
a = set((aa & x for aa in li))
if len(a) < n:
	print(2)
	quit()
print(-1)


fre = [0] * 100001
ftp = [0] * 100001
t = list(map(int, input().split()))
k = list(map(int, input().split()))
val = t[1]
m = list(set(k))
if len(m) != len(k):
	print(0)
else:
	for i in range(t[0]):
		ftp[k[i]] = 1
	for i in range(t[0]):
		fre[k[i]] = fre[k[i]] + 1
		if k[i] != k[i] & val:
			fre[k[i] & val] = fre[k[i] & val] + 1
	count = 0
	shout = 0
	val_l = len(fre)
	for i in range(val_l):
		if fre[i] > 1 and ftp[i] == 0:
			count = count + 1
		elif ftp[i] == 1 and fre[i] > 1:
			shout = shout + 1
			count = 0
			break
	if shout == 0 and count > 0:
		print(2)
	elif shout > 0 and count == 0:
		print(shout)
	else:
		print(-1)


(n, x) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
(s, t) = (set(), set())
ans = 3
for i in a:
	if i in s:
		ans = min(ans, 0)
	elif i in t:
		ans = min(ans, 1)
	elif i & x in s:
		ans = min(ans, 1)
	elif i & x in t:
		ans = min(ans, 2)
	s.add(i)
	t.add(i & x)
print(ans if ans < 3 else -1)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = set()
for i in range(len(a)):
	if a[i] in s:
		print(0)
		exit()
	else:
		s.add(a[i])
for i in range(len(a)):
	if a[i] & m != a[i] and a[i] & m in s:
		print(1)
		exit()
s = set()
for i in range(len(a)):
	if a[i] & m in s:
		print(2)
		exit()
	else:
		s.add(a[i] & m)
print(-1)


from collections import Counter
f = lambda : map(int, input().split())
(n, x) = f()
a = set(f())
if len(a) < n:
	print(0)
else:
	c = Counter((y & x for y in a if y & x != y))
	(b, c) = (set(c.keys()), list(c.most_common(1)) + [(0, 0)])
	print(1 if a & b else 2 if c[0][1] > 1 else -1)


(n, x) = list(map(int, input().split()))
a = set(map(int, input().split()))
if len(a) < n:
	print(0)
else:
	d = set()
	p = 0
	for i in a:
		d.add(i & x)
		if i & x != i and i & x in a:
			print(1)
			p = 1
			break
	if len(d) < n and p == 0:
		print(2)
	elif p != 1:
		print(-1)


R = lambda : map(int, input().split())
(n, x) = R()
(c, d) = (set(R()), set())
a = (2, 0)[len(c) < n]
for y in c:
	if y != y & x and y & x in c:
		a = min(a, 1)
	d |= {y & x}
print((-1, a)[len(d) < n])


import sys
(n, x) = map(int, input().split())
s = list(map(int, input().split()))
dp = [0 for i in range(100004)]
dp1 = [0 for i in range(100004)]
ans = 0
can = False
for i in s:
	dp[i] += 1
	if dp[i] > 1:
		can = True
		break
if can:
	print(0)
	sys.exit()
can = False
can1 = False
for i in range(n):
	y = x & s[i]
	if dp[y] == 1 and y != s[i]:
		can = True
		break
	dp1[y] += 1
	if dp1[y] == 2:
		can1 = True
if can:
	print(1)
elif can1:
	print(2)
else:
	print(-1)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, x) = [int(x) for x in input().split()]
li = set([*map(int, input().split())])
if len(li) < n:
	print(0)
	quit()
for i in li:
	if i & x != i and i & x in li:
		print(1)
		quit()
a = set((aa & x for aa in li))
if len(a) < n:
	print(2)
	quit()
print(-1)


from collections import *
(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
st = set(a)
if len(st) < n:
	print(0)
	return
mp = defaultdict(int)
for i in a:
	mp[i] += 1
for i in a:
	mp[i] -= 1
	if mp[i & m] > 0:
		print(1)
		return
	mp[i] += 1
st.clear()
for i in a:
	t = m
	if i & t in st:
		print(2)
		return
	st.add(i & t)
print(-1)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
s = set(l)
z = set()
if len(s) < n:
	print(0)
	exit()
f = 0
for i in l:
	s.remove(i)
	e = x & i
	if e in s:
		f = 1
		break
	if e in z:
		f = 2
	s.add(i)
	z.add(e)
if f == 1:
	print(1)
	exit()
if f == 2:
	print(2)
	exit()
print(-1)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))

def toSameLen(l, x):
	m = max(max(l), x)
	return m

def same(l1, l2):
	same1 = False
	same2 = False
	d = {}
	for (i, ll) in enumerate(l1):
		try:
			d[ll]
			same1 = True
			if ll == l2[i] or l1[d[ll]] == l2[d[ll]]:
				same2 = True
				break
		except:
			d[ll] = i
	return (same1, same2)
if same(a, a)[0]:
	print(0)
else:
	l = [i & x for i in a]
	(same1, same2) = same(l, a)
	if same1:
		if same2:
			print(1)
		else:
			print(2)
	else:
		print(-1)


[m, n] = map(int, input().split())
a = list(map(int, input().split()))
data = [0] * 100005
ans = -1
for i in a:
	data[i] += 1
pdata = [0] * 100005
for i in range(len(a)):
	a[i] = a[i] & n
	pdata[a[i]] += 1
for i in range(len(pdata)):
	if pdata[i] >= 2 and data[i] >= 1:
		ans = 1
		break
	elif pdata[i] >= 2:
		ans = 2
for i in data:
	if i >= 2:
		ans = 0
print(ans)


n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
m = [0] * (max(a) + 1)
m1 = [0] * (max(a) + 1)
(t, k, r) = (0, 0, 0)
for i in range(n[0]):
	m[a[i]] += 1
	m1[a[i]] += 1
if max(m) > 1:
	print(0)
	exit()
for i in range(n[0]):
	r = a[i] & n[1]
	m[r] += 1
	m[a[i]] -= 1
	m1[r] += 1
	m1[a[i]] -= 1
	if m[r] > 1:
		k = 1
		print(1)
		exit()
	else:
		m[r] -= 1
		m[a[i]] += 1
if max(m1) > 1:
	print(2)
elif k == 0:
	print(-1)
	exit()


(n, x) = map(int, input().split())
a = set(map(int, input().split()))
if len(a) != n:
	print('0')
	exit()
else:
	for i in a:
		if i & x != i and i & x in a:
			print('1')
			exit()
	a = set((i & x for i in a))
	if len(a) != n:
		print('2')
		exit()
print('-1')


(n, x) = (int(x) for x in input().split())
nums = tuple((int(x) for x in input().split()))
num_set = set(nums)
and_set = set()
if len(num_set) < n:
	print(0)
	quit()
for num in nums:
	a = x & num
	if num in and_set:
		print(1)
		quit()
	and_set.add(a)
and_set = set()
for num in nums[::-1]:
	a = x & num
	if num in and_set:
		print(1)
		quit()
	and_set.add(a)
if len(and_set) < n:
	print(2)
	quit()
print(-1)


def main2():
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort()
	count = 9999
	for i in range(len(a) - 1):
		(f, s) = (a[i], a[i + 1])
		if f == s:
			print(0)
			return
		if f & x == s & x:
			if count > 2:
				count = 2
		if f == s & x:
			if count > 1:
				count = 1
	if count == 9999:
		print(-1)
	else:
		print(count)

def main():
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	anded = set()
	count = 9999
	a.sort()
	init = {}
	for (i, e) in enumerate(a):
		if e not in init:
			init[e] = set()
		init[e].add(i)
	for i in range(len(a)):
		f = a[i]
		if i < len(a) - 1:
			s = a[i + 1]
			if f == s:
				print(0)
				return
		fx = f & x
		init[f].remove(i)
		if fx in init and init[fx]:
			if count > 1:
				count = 1
		init[f].add(i)
		if fx in anded:
			if count > 2:
				count = 2
		anded.add(fx)
	if count == 9999:
		print(-1)
	else:
		print(count)
main()


(n, x) = map(int, input().split(' '))
a = list(map(int, input().strip().split(' ')))
b = []
for i in a:
	b.append(i & x)
da = {}
flag = True
for i in a:
	if i in da:
		da[i] += 1
		if da[i] == 2:
			print(0)
			flag = False
			break
	else:
		da[i] = 1
if flag:
	flag = True
	db = {}
	for i in range(len(b)):
		if b[i] in da and b[i] != a[i]:
			flag = False
			print(1)
			break
		elif b[i] in db:
			db[b[i]] += 1
		else:
			db[b[i]] = 1
if flag:
	flag = True
	for i in db:
		if db[i] > 1:
			print(2)
			flag = False
			break
if flag:
	print(-1)


def main():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = set(arr)
	if len(s) != n:
		print(0)
		exit(0)
	ss = set()
	for v in arr:
		ss.add(v & x)
		s.remove(v)
		if v & x in s:
			print(1)
			exit(0)
		s.add(v)
	for v in arr:
		s.remove(v)
		if v & x in s:
			print(1)
			exit(0)
		s.add(v)
	if len(ss) == n:
		print(-1)
	else:
		print(2)
main()


(n, x) = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0 for i in range(max(A) + 1)]
for i in A:
	cnt[i] += 1
if len(set(A)) < n:
	print('0')
else:
	flag = 0
	for i in range(n):
		if cnt[A[i] & x] == 1 and A[i] != A[i] & x:
			flag = 1
	for i in range(n):
		A[i] = A[i] & x
	if flag == 1:
		print('1')
	elif len(set(A)) < n:
		print('2')
	else:
		print('-1')


(n, x) = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
freq = [0] * (max(max(A), x) + 1)
ans = -1
for i in A:
	freq[i] += 1
	if freq[i] == 2:
		ans = 0
ct = 0
new = [0] * len(freq)
for i in A:
	if i & x != i:
		new[i & x] += 1
pos = []
for i in range(len(freq)):
	if freq[i] > 1:
		pos.append(0)
	if new[i] > 0 and freq[i] > 0:
		pos.append(1)
	if new[i] > 1:
		pos.append(2)
if len(pos) > 0:
	ans = min(pos)
print(ans)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, x) = r()
arr = rr()
brr = Counter(arr)
crr = defaultdict(list)
if any((i > 1 for i in brr.values())):
	print(0)
	exit()
for i in arr:
	if i & x != i:
		if brr[i & x]:
			print(1)
			exit()
		else:
			crr[i & x].append(i)
if any((len(i) > 1 for i in crr.values())):
	print(2)
else:
	print(-1)


import sys
import os

def solve(a, x):
	occ = dict()
	for k in a:
		if k in occ:
			return 0
		else:
			occ[k] = True
	two = False
	occx = dict()
	for k in a:
		if k & x == k:
			continue
		elif k & x in occ:
			return 1
		elif k & x in occx:
			two = True
		else:
			occx[k & x] = True
	return 2 if two else -1

def main():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(a, x))

def __starting_point():
	main()
__starting_point()


import sys
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
cnt = [[0, 0] for i in range(max(a) + 1)]
if len(set(a)) < n:
	print(0)
else:
	answ = 3
	for e in a:
		cnt[e][0] += 1
		cnt[e & x][1] += 1
	for e in range(max(a) + 1):
		f = 0
		if cnt[e][0] > 0:
			if e == e & x:
				if cnt[e][1] > 1:
					answ = min(answ, 1)
					f = 1
			elif cnt[e][1] > 0:
				answ = min(answ, 1)
				f = 1
		if not f:
			if cnt[e][1] > 1:
				answ = min(answ, 2)
	if answ == 3:
		print(-1)
	else:
		print(answ)


(n, x) = [int(x) for x in input().split()]
li = [*map(int, input().split())]
if len(li) > len(set(li)):
	print(0)
	quit()
li = set(li)
for i in li:
	if i & x != i and i & x in li:
		print(1)
		quit()
a = set((aa & x for aa in li))
if len(a) < n:
	print(2)
	quit()
print(-1)


import sys
from collections import Counter

def main():
	(_, x, *l) = map(int, sys.stdin.read().strip().split())
	(s, c) = (set(l), Counter())
	if len(s) < len(l):
		return 0
	for i in l:
		a = i & x
		if a in s and a != i:
			return 1
		c[a] += 1
	if c.most_common()[0][1] > 1:
		return 2
	return -1
print(main())


(n, x) = map(int, input().split())
arr = map(int, input().split())
orgin = set()
change = set()
ans = 10
for element in arr:
	if element in orgin:
		ans = min(ans, 0)
	if element in change:
		ans = min(ans, 1)
	if element & x in orgin:
		ans = min(ans, 1)
	if element & x in change:
		ans = min(ans, 2)
	orgin.add(element)
	change.add(element & x)
print(-1 if ans == 10 else ans)
exit(0)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 100001
c = [0] * 100001
for i in a:
	b[i] += 1
	if b[i] >= 2:
		exit(print(0))
for i in a:
	b[i] -= 1
	if b[i & x] >= 1:
		exit(print(1))
	b[i] += 1
for i in a:
	c[i & x] += 1
	if c[i & x] >= 2:
		exit(print(2))
print(-1)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
dict1 = {}
flag1 = 0
for i in range(n):
	try:
		dict1[arr[i]] += 1
		flag1 = 1
		break
	except:
		KeyError
		dict1[arr[i]] = 1
if flag1 == 1:
	print(0)
else:
	dict2 = {}
	flag = 0
	for i in range(n):
		try:
			dict2[arr[i] & x] += 1
			flag = 2
		except:
			KeyError
			dict2[arr[i] & x] = 1
	for i in range(n):
		a = arr[i] & x
		if a != arr[i]:
			try:
				if dict1[a] == 1:
					flag = 1
					break
			except:
				KeyError
	if flag == 1:
		print(1)
	elif flag == 2:
		print(2)
	else:
		print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for e in a:
	d[e] = d.get(e, 0) + 1
for e in d:
	if d[e] >= 2:
		print(0)
		break
else:
	for e in d:
		if not e & x == e:
			if e & x in d:
				print(1)
				break
	else:
		d = {}
		for i in range(n):
			a[i] &= x
			d[a[i]] = d.get(a[i], 0) + 1
		for e in d:
			if d[e] >= 2:
				print(2)
				break
		else:
			print(-1)


(n, x) = map(int, input().split())
L = list(map(int, input().split()))
m = max(L)
A = [0] * (m + 1)
f = 0
for i in range(n):
	A[L[i]] += 1
	if A[L[i]] == 2:
		f = 1
		break
if f == 1:
	print(0)
else:
	k = 0
	L1 = []
	for i in range(len(A)):
		L1.append(A[i])
	for i in range(n):
		p = L[i] & x
		if p != L[i]:
			A[p] += 1
		if A[p] == 2:
			if L1[p] == 0:
				k = 2
			elif L1[p] == 1:
				k = 1
				break
	if k == 1:
		print(1)
	elif k == 2:
		print(2)
	else:
		print(-1)


(n, x) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
b = []
t = {}
ans = -1
if max(d.values()) > 1:
	ans = 0
else:
	for i in range(n):
		if a[i] & x != a[i] and a[i] & x in d:
			ans = 1
			break
		elif a[i] & x not in t:
			t[a[i] & x] = 1
		else:
			t[a[i] & x] += 1
	if ans == -1:
		if max(t.values()) > 1:
			ans = 2
print(ans)


(n, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [False] * (max(a) + 1)
for i in a:
	if f[i]:
		print(0)
		quit()
	f[i] = True
wk1 = []
for i in range(n):
	wk1.append(a[i] & x)
f = [False] * (max(a) + 1)
position = [-1] * (max(a) + 1)
for i in range(n):
	f[a[i]] = True
	position[a[i]] = i
for i in range(n):
	if f[wk1[i]] and position[wk1[i]] != i:
		print(1)
		quit()
f = [False] * (max(wk1) + 1)
for i in wk1:
	if f[i]:
		print(2)
		quit()
	f[i] = True
print(-1)


from sys import stdin, stdout
from itertools import accumulate
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, x) = lst()
	a = lst()
	ans = 0
	s = set(a)
	if len(s) != n:
		print(0)
		continue
	for i in range(n):
		v = a[i]
		a[i] &= x
		if a[i] in s and v != a[i]:
			ans = 1
			break
	if ans == 1:
		print(1)
	elif len(set(a)) == n:
		print(-1)
	else:
		print(2)


from collections import Counter
(n, x) = list(map(int, input().split()))
b = Counter(list(map(int, input().split())))
bs = set(b.keys())
if b.most_common(1)[0][1] > 1:
	print(0)
	return
k = Counter([a & x for a in list(b.keys()) if a & x != a])
ks = set(k.keys())
if len(ks.intersection(bs)) > 0:
	print(1)
	return
if len(k) > 0 and k.most_common(1)[0][1] > 1:
	print(2)
	return
print(-1)


from collections import *
R = lambda : map(int, input().split())
(n, x) = R()
(c, d, e) = (Counter() for _ in [0] * 3)
a = 3
for y in sorted(R()):
	c[y] += 1
	if c[y] > 1:
		a = 0
	if y == y & x:
		d[y] = 1
	e[y & x] += 1
	if e[y & x] > 1:
		a = min(a, 2 - d[y & x])
print((a, -1)[a > 2])


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
d = {}
w = 0
e = 0
f = 0
for i in l:
	d[i] = d.get(i, 0) + 1
for j in list(d.values()):
	if j >= 2:
		ans.append(0)
		f = 1
p = [t & x for t in l]
d2 = {}
for k in p:
	d2[k] = d2.get(k, 0) + 1
for i in range(n):
	if l[i] != p[i]:
		if d.get(p[i], 0):
			ans.append(1)
			e = 1
for z in list(d2.values()):
	if z >= 2:
		ans.append(2)
		w = 1
if w + e + f == 0:
	ans.append(-1)
print(min(ans))


import sys
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
r = set()
r2 = set()
ans = -1
for i in a:
	if i in r:
		print(0)
		sys.exit()
	if i & x in r:
		ans = 1
	if i in r2:
		ans = 1
	if i & x in r2 and ans == -1:
		ans = 2
	r.add(i)
	r2.add(i & x)
print(ans)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
t = {}
ok = False
for i in a:
	try:
		d[i] += 1
	except KeyError:
		d[i] = 1
for i in a:
	if d[i] > 1:
		print(0)
		return
	tmp = x & i
	if tmp != i:
		try:
			t[tmp] += 1
		except KeyError:
			t[tmp] = 1
for i in t:
	try:
		tmp = d[i]
	except KeyError:
		tmp = 0
	if t[i] > 1:
		ok = True
	if t[i] >= 1 and tmp == 1:
		print(1)
		return
if ok:
	print(2)
else:
	print(-1)


(n, x) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

def main():
	a_set = set(a)
	if len(a) != len(a_set):
		return 0
	ax = [ai & x for ai in a]
	ax_set = set(ax)
	for (ai, axi) in zip(a, ax):
		if ai != axi and axi in a_set:
			return 1
	if len(ax) == len(ax_set):
		return -1
	return 2
print(main())


(n, x) = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
(already, one, two) = (0, 0, 0)
hsh_i = [0 for i in range(100001)]
hsh_f = [0 for i in range(100001)]
for i in range(n):
	num = a[i]
	after_and = a[i] & x
	hsh_i[num] += 1
	hsh_f[after_and] += 1
	if hsh_i[num] > 1:
		already = 1
		break
for i in range(n):
	if hsh_i[a[i] & x] > 0 and a[i] != a[i] & x:
		one = 1
		break
for i in range(n):
	if hsh_f[a[i] & x] > 1:
		two = 1
		break
if already:
	print(0)
elif one:
	print(1)
elif two:
	print(2)
else:
	print(-1)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0] * 1000000
ans = 0
go = False
for i in a:
	b[i] += 1
	if b[i] > 1:
		go = True
if go:
	print(ans)
else:
	for i in a:
		b[i] -= 1
		if b[i & x] + 1 > 1:
			go = True
			ans = 1
			break
		b[i] += 1
	if go:
		print(ans)
	else:
		c = [i & x for i in a]
		b = [0] * 1000000
		for i in c:
			b[i] += 1
			if b[i] > 1:
				ans = 2
				go = True
				break
		if go:
			print(ans)
		else:
			print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 100002
for i in range(n):
	b[a[i]] += 1
flag = True
for i in range(len(b)):
	if b[i] > 1:
		print(0)
		flag = False
		break
if flag:
	swag = True
	for i in range(n):
		if b[a[i] & x] == 1 and a[i] & x != a[i]:
			print(1)
			swag = False
			break
	if swag:
		dawg = True
		for i in range(n):
			a[i] &= x
		b = [0] * 100002
		for i in range(n):
			b[a[i]] += 1
			if b[a[i]] >= 2:
				print(2)
				dawg = False
				break
		if dawg:
			print(-1)


t = 1
for test in range(1, t + 1):
	(n, x) = map(int, input().split())
	b = list(map(int, input().split()))
	a = set(b)
	ans = -1
	if len(a) - len(b) < 0:
		ans = 0
	else:
		D = {}
		for i in b:
			if i in D:
				D[i] += 1
			else:
				D[i] = 1
		for i in b:
			if i & x in D:
				if i == i & x:
					if D[i] > 1:
						ans = 1
						break
				else:
					ans = 1
					break
		if ans == -1:
			tmp = []
			for i in b:
				tmp.append(i & x)
			if len(tmp) > len(set(tmp)):
				ans = 2
	print(ans)


(n, x) = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
anded = list(map(lambda z: z & x, arr))
sarr = set(arr)
sanded = set(anded)
if len(sarr) < len(arr):
	print(0)
else:
	d = {}
	for (i, a) in enumerate(anded):
		if a not in d:
			d[a] = set()
		d[a].add(i)
	for (i, e) in enumerate(arr):
		if e in d and (len(d[e]) > 1 or i not in d[e]):
			print(1)
			break
	else:
		if len(sanded) < len(anded):
			print(2)
		else:
			print(-1)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, x) = mp()
arr = lmp()
if len(set(arr)) < n:
	print(0)
else:
	flg = True
	md = dd(int)
	for i in arr:
		md[i] += 1
	for i in arr:
		if i & x != i and md[i & x] > 0:
			print(1)
			flg = False
			break
	if flg:
		nl = []
		for i in arr:
			nl.append(i & x)
		if len(set(nl)) < n:
			flg = False
			print(2)
		if flg:
			print(-1)


def main():
	(n, x) = map(int, input().split())
	l = [0] * 100001
	one = two = 0
	for a in map(int, input().split()):
		if l[a]:
			if l[a] == 1:
				print(0)
				return
			else:
				one = 1
		l[a] = 1
		if a & x != a:
			a &= x
			if l[a]:
				if l[a] == 1:
					one = 1
				else:
					two = 2
			else:
				l[a] = 2
	print(one or two or -1)
main()


(n, x) = map(int, input().split())
arr = set(map(int, input().split()))
flag = 0
if len(arr) < n:
	print(0)
	flag = 1
if flag == 0:
	for item in arr:
		if item & x != item and item & x in arr:
			print(1)
			flag = 1
			break
	if flag == 0:
		a = set((aa & x for aa in arr))
		if len(a) < n:
			print(2)
			flag = 1
	if flag == 0:
		print(-1)


(n, x) = map(int, input().split(' '))
alist = list(map(int, input().split(' ')))
count_dict = {}
new_dict = {}
for index in range(n):
	current_value = alist[index]
	new_value = current_value & x
	count_dict[current_value] = count_dict.get(current_value, 0) + 1
	if new_value != current_value:
		count_dict[new_value] = count_dict.get(new_value, 0) + 1
	new_dict[current_value] = new_dict.get(current_value, 0) + 1
result = '-1'
for (key, val) in new_dict.items():
	if val > 1:
		result = '0'
		break
if result != '0':
	result = '-1'
	for (key, val) in count_dict.items():
		if val > 1 and new_dict.get(key, 0) != 0:
			result = '1'
			break
		if val > 1:
			result = '2'
print(result)


R = lambda : map(int, input().split())
(n, x) = R()
(c, d, e) = (set(R()), set(), set())
d = set((y for y in c if y == y & x))
a = (3, 0)[len(c) < n]
for y in c:
	if y & x in e:
		a = min(a, 2 - (y & x in d))
	e.add(y & x)
print((a, -1)[a > 2])


import sys
import math
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def modst(a, s):
	res = 1
	while s:
		if s % 2:
			res *= a
		a *= a
		s //= 2
	return res

def size(x1, y1, x2, y2):
	return ((x1 + x2) ** 2 + (y1 + y2) ** 2) ** 0.5

def d(sum_size, size_x_y):
	rerurn(sum_size ** 2 - 8 * size_x_y) ** 0.5

def main():
	(n, x) = rinput()
	a = rlinput()
	q = set(a)
	if len(q) < n:
		print(0)
	else:
		w = []
		for i in a:
			if i & x != i:
				w.append(i & x)
		if set(w) & q:
			print(1)
		elif len(set(w)) < len(w):
			print(2)
		else:
			print(-1)
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, x) = ria()
		a = ria()
		d = Counter(a)
		sa = set(a)
		if len(sa) < n:
			print(0)
		else:
			c = 0
			for i in a:
				k = i & x
				if k != i and k in d:
					c = 1
					print(1)
					break
			if c == 0:
				z = []
				for i in a:
					z.append(i & x)
				if len(set(z)) < n:
					print(2)
				else:
					print('-1')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


(n, x) = map(int, input().split())
m = list(map(int, input().split()))
k = [0] * (max(m) + 1)
log = True
log2 = True
log3 = True
for i in range(n):
	if k[m[i]] == 0:
		k[m[i]] = 1
	else:
		print(0)
		log = False
		log2 = False
		log3 = False
		break
if log:
	log2 = True
	for i in range(n):
		if m[i] & x != m[i]:
			if k[m[i] & x] != 0:
				print(1)
				log2 = False
				log3 = False
				break
if log2:
	log3 = True
	k = [0] * (max(m) + 1)
	for i in range(n):
		if k[m[i] & x] == 1:
			print(2)
			log3 = False
			break
		else:
			k[m[i] & x] = k[m[i] & x] + 1
if log3:
	print(-1)


can11 = set()
can12 = set()
can2 = False
(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
for ai in a:
	if ai in can11:
		print('0')
		break
	can11.add(ai)
	ai2 = ai & x
	if ai2 == ai:
		continue
	if ai2 in can12:
		can2 = True
	else:
		can12.add(ai2)
else:
	can11.intersection_update(can12)
	if can11:
		print(1)
	elif can2:
		print(2)
	else:
		print('-1')


(n, x) = list(map(int, input().split()))
arr = list(map(int, input().split()))
f = [0] * 100100
s = [0] * 100100
can = [False] * 100100
for i in range(n):
	f[arr[i]] += 1
	s[arr[i] & x] += 1
	if arr[i] & x != arr[i]:
		can[arr[i] & x] = True
ans = 3
for i in range(len(f)):
	if f[i] >= 2:
		ans = 0
		break
	if f[i] == 1 and s[i] >= 1:
		if can[i]:
			ans = min(ans, 1)
	if s[i] >= 2:
		ans = min(ans, 2)
if ans == 3:
	print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
hm = [0] * 100010
hm1 = [0] * 100010
for i in l:
	if hm[i]:
		print(0)
		exit(0)
	else:
		hm[i] += 1
for i in l:
	z = k & i
	if z != i:
		if hm[z]:
			print(1)
			exit(0)
		else:
			hm1[z] += 1
for i in hm1:
	if i > 1:
		print(2)
		exit(0)
print(-1)


(n, x) = map(int, input().split())
a = [int(x) for x in input().split()]
c1 = {}
c2 = {}
for cnt in range(n):
	i = a[cnt]
	if i in c1:
		print(0)
		exit()
	else:
		c1[i] = cnt
two = False
for cnt in range(n):
	j = a[cnt]
	i = j & x
	if i in c1 and c1[i] != cnt:
		print(1)
		exit()
	elif i in c2:
		two = True
	else:
		c2[i] = 1
if two:
	print(2)
else:
	print(-1)


I = lambda : map(int, input().split())
(n, x) = I()
A = set(I())
if len(A) < n:
	print(0)
else:
	for a in A:
		if a & x != a and a & x in A:
			print(1)
			break
	else:
		if len({a & x for a in A}) < n:
			print(2)
		else:
			print(-1)


(n, x) = map(int, input().split())
s = [int(x) for x in input().split()]
kk = dict()
kk1 = dict()
temp = 0
for i in range(0, len(s)):
	if kk.get(s[i]) == None:
		kk[s[i]] = 1
	else:
		kk[s[i]] += 1
		temp = 1
if temp == 1:
	print(0)
else:
	for i in range(0, len(s)):
		if kk.get(s[i] & x) != None:
			if s[i] == s[i] & x:
				if kk[s[i] & x] > 1:
					tenp = 1
			else:
				temp = 1
	if temp == 1:
		print(1)
	else:
		for i in range(0, len(s)):
			if kk1.get(s[i] & x) == None:
				kk1[s[i] & x] = 1
			else:
				kk1[s[i] & x] += 1
				temp = 1
		if temp == 1:
			print(2)
		else:
			print(-1)


import sys

def main():
	lines = []
	for line in sys.stdin:
		lines.append(line)
	n = int(lines[0].split(' ')[0])
	x = int(lines[0].split(' ')[1])
	inputs = {int(a): i for (i, a) in enumerate(lines[1].split(' '))}
	if len(inputs) != n:
		print(0)
		return
	ops = -1
	ands = {}
	for (a, i) in inputs.items():
		a2 = a & x
		if a2 in inputs and inputs[a2] != i:
			ops = 1
		if a2 in ands and ops == -1:
			ops = 2
		ands[a2] = i
	print(ops)
main()


(n, k) = map(int, input().split())
no = list(map(int, input().split()))
s = set()
for i in no:
	s.add(i)
f = 0
if len(s) < n:
	f = 1
if f == 1:
	print(0)
else:
	coun = [0] * 100005
	for i in no:
		coun[i] += 1
	for i in no:
		temp = i & k
		if temp != i and coun[temp] > 0:
			f = 1
			break
	if f == 1:
		print(1)
	else:
		coun = [0] * 100005
		for i in range(n):
			no[i] = no[i] & k
			coun[no[i]] += 1
		for i in no:
			if coun[i] > 1:
				f = 1
				break
		if f == 1:
			print(2)
		else:
			print(-1)


(n, x) = list(map(int, input().split()))
l = list(map(int, input().split()))
a = [0] * (10 ** 5 + 1)
b = [0] * (10 ** 5 + 1)
count = 0
flag = 0
for i in range(n):
	if a[l[i] - 1] == 0:
		a[l[i] - 1] = 1
	else:
		count = 0
		flag = 1
if flag == 0:
	for i in range(n):
		if a[(l[i] & x) - 1] == 1 and l[i] & x != l[i]:
			count = 1
			break
		elif b[(l[i] & x) - 1] == 1:
			count = 2
		b[(l[i] & x) - 1] = 1
if flag == 0 and count == 0:
	print('-1')
else:
	print(count)


import sys
import math

def main():
	(n, x) = list(map(int, sys.stdin.readline().strip().split(' ')))
	a = list(map(int, sys.stdin.readline().strip().split(' ')))
	s = dict()
	s1 = dict()
	for (i, e) in enumerate(a):
		if e in s:
			sys.stdout.write(str(0))
			return
		s[e] = i
	for (i, e) in enumerate(a):
		if e & x in s and s[e & x] != i:
			sys.stdout.write(str(1))
			return
		s1[e & x] = i
	for (i, e) in enumerate(a):
		if e & x in s1 and s1[e & x] != i:
			sys.stdout.write(str(2))
			return
	sys.stdout.write(str(-1))
main()


from collections import Counter
(n, x) = map(int, input().split())
t = list(map(int, input().split()))
a = Counter()
b = Counter()
for i in t:
	a[i & x] += 1
	b[i] += 1
for i in b:
	if b[i] > 1:
		print(0)
		exit()
mini = -1
for i in a:
	if a[i] >= 1:
		if b[i] == 1 and a[i] >= 2:
			print(1)
			exit()
		elif a[i] >= 2:
			mini = 2
print(mini)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var):
	print(*var, file=sys.stderr)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, x) = I()
a = I()
ans = 0
s = set(a)
if len(s) != n:
	print(ans)
	exit()
d = {}
a.sort()
s = set()
k = set()
ans = 3
for i in range(n):
	if a[i] & x in k:
		ans = 1
		break
	elif a[i] & x in s:
		ans = 2
	s.add(a[i] & x)
	k.add(a[i])
if ans == 3:
	print(-1)
else:
	print(ans)


import bisect
s = input().split()
(n, x) = (int(s[0]), int(s[1]))
s = input().split()
l = [None] * n
ll = [None] * n
for i in range(n):
	l[i] = int(s[i])
	ll[i] = int(s[i]) & x
l.sort()
ll.sort()
res = -1
for i in range(n - 1):
	if l[i] == l[i + 1]:
		res = 0
		break
if res == -1:
	for i in range(n - 1):
		if ll[i] == ll[i + 1]:
			ind = bisect.bisect_left(l, ll[i])
			if l[ind] == ll[i]:
				res = 1
				break
			elif res == -1:
				res = 2
print(res)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
s = set(a)
if len(s) < len(a):
	print(0)
else:
	b = [i & x for i in a if i & x != i]
	if any((i in s for i in b)):
		print(1)
	elif len(set(b)) < len(b):
		print(2)
	else:
		print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
s = set(a)
mv = 999
if len(s) < n:
	print(0)
else:
	for i in a:
		if i & x != i and i & x in s:
			print(1)
			break
	else:
		k = [i & x for i in a]
		if len(set(k)) < n:
			print(2)
		else:
			print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i] & x for i in range(n)]
da = {}
db = {}
flag = -1
for i in range(len(a)):
	if a[i] not in da:
		da[a[i]] = 1
	else:
		print(0)
		flag = 0
		break
if flag != 0:
	for i in range(n):
		if b[i] in da and a[i] != b[i]:
			print(1)
			exit(0)
		if b[i] not in db:
			db[b[i]] = 1
		else:
			flag = 2
	print(flag)


(n, x) = map(int, input().split())
c = set(map(int, input().split()))
if len(c) < n:
	k = 0
else:
	ct = set()
	k = -1
	for i in c:
		ct.add(i & x)
		if i & x != i and i & x in c:
			k = 1
	if len(ct) < len(c) and k == -1:
		k = 2
print(k)


(N, X) = map(int, input().split())
B = list(map(int, input().split()))
C = [0 for _ in range(100001)]
for x in B:
	C[x] += 1
	if C[x] >= 2:
		print(0)
		exit(0)
for x in B:
	if C[x & X] == 1 and x & X != x:
		print(1)
		exit(0)
for x in B:
	C[x] -= 1
	C[x & X] += 1
	if C[x & X] >= 2:
		print(2)
		exit(0)
print(-1)


(n, x) = map(int, input().split())
lst = set(map(int, input().split()))
l = len(lst)
if l < n:
	print(0)
else:
	nlst = []
	f = 0
	for ele in lst:
		a = ele & x
		if a != ele and a in lst:
			print(1)
			f = 1
			break
		nlst.append(a)
	if f == 0:
		nlst = set(nlst)
		if len(nlst) < n:
			print(2)
			f = 1
	if f == 0:
		print(-1)


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
d = {}
ansz = 0
for i in l:
	if i in d:
		ansz = 1
	else:
		d[i] = 1
lz = []
ans1 = 0
for i in l:
	lz.append(i & m)
	if i & m in d and i & m != i:
		ans1 = 1
ans2 = 0
dz = {}
for i in lz:
	if i in dz:
		ans2 = 1
	else:
		dz[i] = 1
if ansz:
	print(0)
elif ans1:
	print(1)
elif ans2:
	print(2)
else:
	print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
dp = [10 ** 9 for i in range(max(a) + 1)]
for i in range(n):
	if dp[a[i]] == 0:
		print(0)
		return
	dp[a[i]] = 0
j = len(dp) - 1
ans = 10 ** 9
while j >= 0:
	if dp[j] != 10 ** 9:
		if dp[j & x] != 10 ** 9 and j != j & x:
			ans = min(ans, dp[j & x] + dp[j] + 1)
		dp[j & x] = min(dp[j & x], dp[j] + 1)
	j -= 1
if ans == 10 ** 9:
	print(-1)
	return
print(ans)


from sys import stdin, stdout
(n, x) = tuple(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
biggest = max(max(arr) + 1, x + 1)
lookup = [0] * biggest
done = False
for v in arr:
	if lookup[v] > 0:
		print(0)
		done = True
		break
	else:
		lookup[v] += 1
is_two = False
if not done:
	lookup_and = [0] * biggest
	for a in arr:
		v = a & x
		if v != a and lookup[v] > 0:
			print(1)
			done = True
			break
		if lookup_and[v] > 0:
			is_two = True
		else:
			lookup_and[v] += 1
if not done:
	if is_two:
		print(2)
	else:
		print(-1)


from sys import stdin, exit

def listInput():
	return list(map(int, stdin.readline().rstrip().split()))
(n, x) = listInput()
li = listInput()
dic1 = {}
for i in li:
	if i in dic1:
		dic1[i] += 1
	else:
		dic1[i] = 1
dic2 = {}
for i in li:
	if i & x in dic2:
		dic2[i & x] += 1
	else:
		dic2[i & x] = 1
ans = n + 1
for i in li:
	if dic1[i] >= 2:
		ans = min(ans, 0)
	elif i != i & x and i & x in dic1:
		ans = min(ans, 1)
	elif i & x in dic1 and dic1[i & x] >= 2:
		ans = min(ans, 1)
	elif i != i & x and i in dic2:
		ans = min(ans, 1)
	elif i & x in dic2 and dic2[i & x] >= 2:
		ans = min(ans, 2)
if ans == n + 1:
	print(-1)
else:
	print(ans)


def main():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	set_a = set(a)
	if len(set_a) < n:
		print(0)
		return
	cals = [None] * n
	for i in range(n):
		cur = a[i] & x
		if cur != a[i] and cur in set_a:
			print(1)
			return
		cals[i] = cur
	print(2 if len(set(cals)) < n else -1)
main()


(n, x) = list(map(int, input().split()))
a = set((int(i) for i in input().split()))
if len(a) != n:
	ans = 0
else:
	shift = set()
	ans = -1
	for i in a:
		shift.add(i & x)
		if i & x != i and i & x in a:
			ans = 1
	if len(shift) != n and ans == -1:
		ans = 2
print(ans)


(n, xa) = map(int, input().split())
a = list(map(int, input().split()))
c1 = [0] * (max(a) + 1)
fl = -1
for i in range(n):
	x = a[i]
	c1[x] += 1
for i in range(max(a) + 1):
	if c1[i] >= 2:
		fl = 0
		break
if fl == -1:
	for i in range(n):
		x = a[i] & xa
		y = a[i]
		c1[y] -= 1
		c1[x] += 1
		if c1[x] == 2:
			fl = 1
			break
		else:
			c1[x] -= 1
			c1[y] += 1
	if fl == -1:
		for i in range(n):
			x = a[i] & xa
			y = a[i]
			c1[y] -= 1
			c1[x] += 1
			if c1[x] == 2:
				fl = 2
				break
print(fl)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))

def solve(a, x):
	s = set(a)
	if len(s) != len(a):
		return 0
	s1 = set()
	for val in a:
		new = val & x
		if new != val and new in s:
			return 1
		s1.add(new)
	if len(s) != len(s1):
		return 2
	return -1
print(solve(a, x))


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
v = set(a)
b = set()
k = 0
if len(a) == len(v):
	for i in range(len(a)):
		if a[i] & x in v and a[i] & x != a[i]:
			print(1)
			k = 1
			break
	if k != 1:
		for i in range(len(a)):
			if a[i] & x in b:
				print(2)
				k = 1
				break
			else:
				b.add(a[i] & x)
	if k == 0:
		print(-1)
else:
	print(0)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
s = set(c)
if len(c) != len(s):
	print(0)
else:
	c1 = set()
	f = False
	for i in s:
		y = i & x
		if y != i and y in s:
			f = True
			print(1)
			break
		c1.add(y)
	if not f:
		if len(c1) == len(s):
			print(-1)
		else:
			print(2)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = set(map(int, input().split()))
ans = 0
if len(l) != n:
	print(0)
else:
	tem = set()
	ans = -1
	for i in l:
		tem.add(i & k)
		if i & k != i and i & k in l:
			ans = 1
			break
	if len(tem) != n and ans == -1:
		ans = 2
	print(ans)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
ans = 100
o = set()
c = set()
for i in range(n):
	if a[i] in o:
		ans = min(ans, 0)
	elif a[i] in c:
		ans = min(ans, 1)
	elif a[i] & x in o:
		ans = min(ans, 1)
	elif a[i] & x in c:
		ans = min(ans, 2)
	o.add(a[i])
	c.add(a[i] & x)
print(-1 if ans == 100 else ans)


from sys import stdin, stdout
(n, x) = stdin.readline().split()
(n, x) = (int(n), int(x))
arr = [int(y) for y in stdin.readline().split()]
arr.sort()
flag = 0
for i in range(len(arr) - 1):
	if arr[i] == arr[i + 1]:
		print(0)
		flag = 1
		break
if flag == 0:
	arr1 = [arr[i] & x for i in range(len(arr))]
	arr2 = [(arr1[i], arr[i]) for i in range(len(arr))]
	arr2 = sorted(arr2, key=lambda x: x[0])
	currentAns = -1
	for i in range(len(arr2) - 1):
		if arr2[i][0] == arr2[i + 1][0]:
			if arr2[i][0] == arr2[i][1] or arr2[i + 1][0] == arr2[i + 1][1]:
				currentAns = 1
				flag = 1
				break
			else:
				currentAns = 2
	print(currentAns)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
d = len(set(a))
f = []
if d < n:
	print(0)
	exit(0)
b = [0] * 100002
c = [0] * 100002
for i in a:
	b[i] = 1
	e = i & x
	f.append(e)
	if e != i:
		c[e] = 1
k = 0
y = 0
if len(set(f)) < n:
	y = 2
for i in range(100002):
	if b[i] == 1 and b[i] == c[i]:
		k += 1
if k == 0 and y == 0:
	print(-1)
elif y == 2 and k == 0:
	print(2)
elif y == 2 and k != 0:
	print(1)
elif y == 0:
	print(1)


(n, x) = list(map(int, input().split()))
data = list(map(int, input().split()))
s = set(data)
if len(s) < len(data):
	print(0)
	return
answer = -1
ss = set()
prevs = set()
for el in data:
	curr = el & x
	if curr in prevs or el in ss:
		answer = 1
	prevs.add(el)
	if curr in ss and answer != 1:
		answer = 2
	ss.add(curr)
print(answer)


(n, x) = [int(x) for x in input().split()]
a = [int(i) for i in input().split()]
z = 0
if len(set(a)) < len(a):
	print(0)
else:
	b = [x & a[i] for i in range(n)]
	if len(set(b)) < len(b):
		z = 2
	b = [(b[i], i, 1) for i in range(n)]
	r = 0
	a = [(a[i], i, 0) for i in range(n)]
	c = list(sorted(a + b, key=lambda x: x[0]))
	for i in range(2 * n - 1):
		if c[i][0] == c[i + 1][0] and c[i][2] != c[i + 1][2] and (c[i][1] != c[i + 1][1]):
			print(1)
			r = 1
			break
	if r == 0:
		for i in range(2 * n - 2):
			if c[i][0] == c[i + 2][0] and c[i][2] != c[i + 2][2] and (c[i][1] != c[i + 2][1]):
				print(1)
				r = 1
				break
	if r == 0:
		if z == 2:
			print(2)
		else:
			print(-1)


from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import sys
(n, x) = map(int, input().split())
l = list(map(int, input().split()))
hash = defaultdict(int)
for i in l:
	hash[i] += 1
	if hash[i] > 1:
		print(0)
		exit()
se = set(l)
seti = []
for i in l:
	if i & x != i:
		seti.append(i & x)
for i in seti:
	if i in se:
		print(1)
		exit()
hash = defaultdict(int)
for i in seti:
	hash[i] += 1
	if hash[i] > 1:
		print(2)
		exit()
print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
mark = [0] * 100005
for it in a:
	if mark[it] >= 1:
		print('0')
		exit(0)
	mark[it] += 1
for it in a:
	mark[it] -= 1
	if mark[it & x] >= 1:
		print(1)
		exit(0)
	mark[it] += 1
mark = [0] * 100005
for it in a:
	if mark[it & x] >= 1:
		print('2')
		exit(0)
	mark[it & x] += 1
print(-1)


(n, x) = map(int, input().split())
A = list(map(int, input().split()))
if len(A) != len(set(A)):
	print(0)
	exit(0)
Q = []
for i in A:
	if i & x != i:
		Q.append(i & x)
if len(set(Q).intersection(set(A))) > 0:
	print(1)
elif len(set(Q)) != len(Q):
	print(2)
else:
	print(-1)


(n, x) = map(int, input().split())
a = [int(s) for s in input().split()]
b = False
m = 3
d = {}
t = {}
for i in range(n):
	if a[i] in d.keys():
		print(0)
		b = True
		break
	else:
		d[a[i]] = 1
if b == False:
	for el in a:
		if el & x != el and el & x in d.keys():
			print(1)
			b = True
			break
	else:
		for el in a:
			if el & x not in t.keys():
				t[el & x] = 1
			else:
				print(2)
				b = True
				break
if b == False:
	print(-1)


(n, x) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
S = set()
T = set()
ans = 10 ** 18
for a in A:
	if a in S:
		ans = min(ans, 0)
	elif a & x in S:
		ans = min(ans, 1)
	elif a & x in T:
		ans = min(ans, 2)
	S.add(a)
	T.add(a & x)
if ans == 10 ** 18:
	print(-1)
else:
	print(ans)


def main():
	N = 100000
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	exists_before = [False for i in range(N + 1)]
	exists_after = [False for i in range(N + 1)]
	ans = -1
	for i in range(n):
		if exists_before[a[i]]:
			ans = 0
			break
		exists_before[a[i]] = True
	if ans == 0:
		print(ans)
		return
	for i in range(n):
		y = a[i] & x
		if exists_before[y] and y != a[i]:
			ans = 1
			break
		if exists_after[y]:
			ans = 2
		else:
			exists_after[y] = True
	print(ans)
main()


(n, x) = [int(s) for s in input().split()]
a = {int(s) for s in input().split()}
a1 = set()
if len(a) < n:
	print(0)
else:
	ans = 0
	for i in a:
		n = i & x
		if n != i and n in a:
			ans = 1
			break
		elif n in a1:
			ans = 2
		else:
			a1.add(n)
	if ans:
		print(ans)
	else:
		print(-1)


import bisect as bis
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
stt = -1
i = 0
while i < n - 1:
	if a[i] == a[i + 1]:
		stt = 0
		break
	i += 1
if stt == 0:
	pass
else:
	b = [e & k for e in a]
	for (i, e) in enumerate(b):
		if e > a[i]:
			x = bis.bisect(a, e, i + 1)
			if e == a[x - 1]:
				stt = 1
				break
		elif e < a[i]:
			x = bis.bisect(a, e, 0, i)
			if e == a[x - 1]:
				stt = 1
				break
	if stt == -1:
		b = sorted(b)
		i = 0
		while i < n - 1:
			if b[i] == b[i + 1]:
				stt = 2
				break
			i += 1
print(stt)


import sys
(n, x) = map(int, input().split())
a = set([int(x) for x in input().split()])
if len(a) < n:
	print(0)
	sys.exit()
for i in a:
	if i & x != i and i & x in a:
		print(1)
		sys.exit()
s = set((i & x for i in a))
if len(s) < n:
	print(2)
	sys.exit()
print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 100001
for i in a:
	b[i] += 1
for i in range(100000, 0, -1):
	if b[i] > 0:
		if b[i] > 1:
			print(0)
			exit()
for i in range(100000, 0, -1):
	if b[i] > 0:
		p = i & x
		k = b[i]
		b[i] = 0
		if b[i & x] > 0:
			print(1)
			exit()
		b[i] = k
for i in range(100000, 0, -1):
	if b[i] > 0:
		p = i & x
		k = b[i]
		b[i] = 0
		if b[p] == -1:
			print(2)
			exit()
		b[p] = -1
		b[i] = k
print(-1)


import sys
from collections import Counter, defaultdict
(n, x) = map(int, input().split())
d = defaultdict(dict)
for y in map(int, input().split()):
	y1 = y & x
	if y in d[y1]:
		print(0)
		sys.exit()
	else:
		d[y1][y] = 1
L = Counter({y: len(preim) for (y, preim) in d.items()})
maxfreq = L.most_common(1)
if maxfreq[0][1] == 1:
	answer = -1
else:
	answer = 2
	for (y, count) in [(k, v) for (k, v) in L.items() if v > 1]:
		if y in d[y]:
			answer = 1
			break
print(answer)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
A = set()
B = set()
z = 0
o = 0
t = 0
for i in range(n):
	if a[i] in B:
		z = 1
	if a[i] in A:
		o = 1
	if a[i] & x in B:
		o = 1
	if a[i] & x in A:
		t = 1
	B.add(a[i])
	A.add(a[i] & x)
if z:
	print(0)
elif o:
	print(1)
elif t:
	print(2)
else:
	print(-1)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
prev = set()
done = set()
is_same = False
is_once = False
is_twice = False
for v in a:
	if v in prev:
		is_same = True
		break
	elif v in done or v & x in prev:
		is_once = True
	elif v & x in done:
		is_twice = True
	prev.add(v)
	if v & x != v:
		done.add(v & x)
if is_same:
	print(0)
elif is_once:
	print(1)
elif is_twice:
	print(2)
else:
	print(-1)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
if len(set(l)) < n:
	print(0)
else:
	d = {}
	ans = []
	for i in l:
		d[i] = 1
	for i in l:
		if i != i & x:
			if i & x in d:
				ans.append(d[i & x])
			else:
				d[i & x] = 2
	if len(ans) != 0:
		print(min(ans))
	else:
		print(-1)


(N, X) = map(int, input().strip().split())
Ns = list(map(int, input().strip().split()))
dic = {}
done = False
for n in Ns:
	if n in dic:
		print(0)
		done = True
		break
	else:
		dic[n] = 0
if not done:
	double_entry = False
	for n in Ns:
		new_n = n & X
		if n == new_n:
			continue
		if new_n in dic:
			if dic[new_n] == 0:
				print(1)
				done = True
				break
			else:
				double_entry = True
		else:
			dic[new_n] = 1
	if not done:
		if double_entry:
			print(2)
		else:
			print(-1)


[n, x] = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]

def foo():
	nonlocal x, n, nums
	a_plain = set()
	for i in range(n):
		if nums[i] not in a_plain:
			a_plain.add(nums[i])
		else:
			print(0)
			return
	for i in range(n):
		if nums[i] & x in a_plain and nums[i] & x != nums[i]:
			print(1)
			return
	a_and = {}
	for i in range(n):
		temp = nums[i] & x
		if temp not in a_and:
			a_and[temp] = 1
		else:
			a_and[temp] += 1
	for k in a_and:
		if a_and[k] > 1:
			print(2)
			return
	print(-1)
foo()


(n, x) = map(int, input().split())
l = [int(i) for i in input().split()]
k = len(set(l))
if k < n:
	print(0)
	exit()
d = {}
from collections import Counter
c = Counter(l)
from collections import defaultdict
d = defaultdict(int)
cnt = -1
for i in l:
	if c[i & x] > 1:
		print(1)
		exit()
	if c[i & x] == 1 and i != i & x:
		print(1)
		exit()
l1 = [i & x for i in l]
if len(set(l1)) < n:
	print(2)
	exit()
print(-1)


from collections import defaultdict
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) < n:
	print(0)
	exit()
a_nd = [el & x for el in a]
ToF = [a[i] == a_nd[i] for i in range(n)]
c = ToF.count(True)
numb = len(set(a) | set(a_nd))
if c == n or numb == 2 * n:
	print(-1)
	exit()
numb2 = len(set(a) & set(a_nd))
l_and = len(set(a_nd))
if numb2 == 0 and l_and < n:
	print(2)
	exit()
C = defaultdict(int)
for el in a:
	C[el] += 1
for i in range(n):
	C[a[i]] -= 1
	if C[a_nd[i]] > 0:
		print(1)
		exit()
	C[a[i]] += 1
if l_and < n:
	print(2)
	exit()
print(-1)


(n, x) = map(int, input().split())
a = [0] * 100001
inp = list(map(int, input().split()))
for i in range(n):
	a[inp[i]] += 1
b = [0] * 100001
flag1 = False
flag2 = False
flag3 = False
for i in range(1, 100001):
	if a[i] > 1:
		flag1 = True
	elif a[i] == 1:
		a[i] = 0
		if a[i & x] == 1:
			flag2 = True
		elif b[i & x] == 1:
			flag3 = True
		a[i] = 1
		b[i & x] += 1
if flag1:
	print(0)
elif flag2:
	print(1)
elif flag3:
	print(2)
else:
	print(-1)


import sys
import bisect
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(len(a) - 1):
	if a[i] == a[i + 1]:
		print(0)
		sys.exit()
b = list()
for i in range(len(a)):
	k = bisect.bisect_left(a, a[i] & x)
	if k != len(a):
		if a[k] == a[i] & x:
			if k != i:
				print(1)
				sys.exit()
			elif k + 1 < len(b) and a[k + 1] == a[i] & x:
				print(1)
				sys.exit()
			else:
				b.append(a[i] & x)
		else:
			b.append(a[i] & x)
b.sort()
for i in range(len(b) - 1):
	if b[i] == b[i + 1]:
		print(2)
		sys.exit()
print(-1)


(n, x) = map(int, input().split())
l = set(map(int, input().split()))
if len(l) < n:
	print(0)
	exit()
for i in l:
	if i & x != i and i & x in l:
		print(1)
		exit()
s = set((i & x for i in l))
if len(s) < n:
	print(2)
	exit()
print(-1)


import heapq
from math import sqrt
from collections import defaultdict
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
raw = defaultdict(int)
raw_ = defaultdict(int)
change = defaultdict(int)
for v in a:
	if raw[v]:
		print(0)
		exit()
	raw[v] += 1
raw.clear()
for v in a:
	c = v & x
	if raw[c]:
		print(1)
		exit()
	if raw_[v]:
		print(1)
		exit()
	raw_[c] += 1
	raw[v] += 1
for v in a:
	c = v & x
	if change[c]:
		print(2)
		exit()
	change[c] += 1
print(-1)


def main():
	(n, x) = [int(x) for x in input().split()]
	a = set([int(x) for x in input().split()])
	if len(a) != n:
		ans = 0
	else:
		offsets = set()
		ans = -1
		for i in a:
			curr = i & x
			offsets.add(curr)
			if curr in a and curr != i:
				ans = 1
		if len(offsets) != n and ans == -1:
			ans = 2
	print(ans)
main()


fistStr = list(map(int, input().split(' ')[:2]))
x = fistStr[1]
secondStr = list(map(int, input().split(' ')[:fistStr[0]]))
setStr = set()
for i in range(len(secondStr)):
	setStr.add(secondStr[i])
if len(setStr) < len(secondStr):
	print(0)
	exit(0)
for i in range(len(secondStr)):
	setStr.remove(secondStr[i])
	setStr.add(secondStr[i] & x)
	if len(setStr) != len(secondStr):
		print(1)
		exit(0)
	setStr.remove(secondStr[i] & x)
	setStr.add(secondStr[i])
setStr.clear()
for i in range(len(secondStr)):
	setStr.add(secondStr[i] & x)
if len(setStr) != len(secondStr):
	print(2)
	exit(0)
print(-1)


(n, x) = map(int, input().split())
a = [int(i) for i in input().split()]
aset = set(a)
if len(a) - len(aset) > 0:
	print(0)
	exit(0)
b = []
flag = False
for i in range(n):
	bc = a[i] & x
	if bc != a[i] and bc in aset:
		flag = True
		break
	b.append(bc)
if flag:
	print(1)
elif len(b) - len(set(b)) > 0:
	print(2)
else:
	print(-1)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
N = 100005
dp = [[False, False] for i in range(N)]
ans = 3
for val in arr:
	if dp[val][0]:
		ans = 0
	if dp[val][1]:
		ans = min(ans, 1)
	temp = val
	val &= x
	if dp[val][1]:
		ans = min(ans, 2)
	if dp[val][0]:
		ans = min(ans, 1)
	dp[val][1] = True
	dp[temp][0] = True
if ans != 3:
	print(ans)
else:
	print('-1')


import collections as cl
(n, x) = map(int, input().split())
a = cl.Counter(map(int, input().split()))
b = cl.Counter(map(x.__and__, a))
if len(a) < n:
	print(0)
else:
	b = list(sorted(b.items(), key=lambda x: (x[1], x[0]), reverse=True))
	for i in range(len(b)):
		if b[i][1] > 1:
			if b[i][0] in a.keys():
				print(1)
				break
		else:
			if i > 0:
				print(2)
			else:
				print(-1)
			break
	else:
		print(2)


a = input()
l = list(map(int, a.split()))
n = l[0]
x = l[1]
b = input()
r = list(map(int, b.split()))
arr1 = []
arr2 = []
val = []
sec = []
vis = 0
ans = 1000000
for i in range(1, 100002):
	val.append(0)
	sec.append(0)
for i in range(len(r)):
	c = r[i]
	d = r[i] & x
	arr1.append(c)
	arr2.append(d)
	val[c] = val[c] + 1
	if val[c] > 1:
		ans = min(ans, 0)
	sec[d] = sec[d] + 1
	if sec[d] > 1:
		ans = min(ans, 2)
for i in range(len(r)):
	if arr1[i] == arr2[i]:
		if val[arr2[i]] > 1:
			ans = min(ans, 0)
	elif val[arr2[i]] == 1:
		ans = min(ans, 1)
if ans == 1000000:
	print(-1)
else:
	print(ans)


(n, x) = map(int, input().split())
a = set(map(int, input().split()))
if len(a) != n:
	print(0)
else:
	anew = set()
	for k in a:
		knew = k & x
		if knew != k and knew in a:
			print(1)
			exit()
		anew.add(knew)
	if len(anew) != n:
		print(2)
	else:
		print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = set(a)
c = set()
res = 0
if len(b) < n:
	print(0)
else:
	for i in a:
		if i & x == i:
			continue
		if i & x in b:
			print(1)
			exit(0)
		elif i & x in c:
			res = 2
		else:
			c.add(i & x)
	if res == 2:
		print(res)
	else:
		print(-1)


import sys
from collections import defaultdict
(n, c) = map(int, input().split())
a = [int(x) for x in input().split()]
d = []
l = defaultdict(int)
l2 = defaultdict(int)
ans = -1
for x in a:
	d.append(x)
	l[x] += 1
	if l[x] > 1:
		print(0)
		sys.exit(0)
	l2[x & c] += 1
	if l2[x & c] > 1:
		ans = 2
for x in d:
	l[x] -= 1
	if l[x & c] > 0:
		ans = 1
		break
	l[x] += 1
print(ans)


import sys
(n, x) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
check = 0
for i in range(1, n):
	if A[i] == A[i - 1]:
		check = 1
		break
if check == 1:
	print(0)
	sys.exit()
B = [A[i] for i in range(n)]
for i in range(n):
	A[i] = A[i] & x
AX = [(A[i], i) for i in range(n)]
AX.sort()
check = 0
i = 0
j = 0
while i < n:
	if AX[i][0] == B[j]:
		if AX[i][1] != j:
			check = 1
			break
		else:
			i += 1
	elif AX[i][0] < B[j]:
		i += 1
	elif AX[i][0] > B[j]:
		j += 1
if check == 1:
	print(1)
	sys.exit()
check = 0
for i in range(1, n):
	if AX[i][0] == AX[i - 1][0]:
		check = 1
		break
if check == 1:
	print(2)
	sys.exit()
print(-1)


from collections import Counter
(n, x) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if Counter(A).most_common()[0][1] >= 2:
	print(0)
	return
setA = set(A)
B = []
for a in A:
	B.append(a & x)
ans = -1
for (b, c) in Counter(B).most_common():
	if c >= 2:
		if b in setA:
			ans = 1
			break
		else:
			ans = 2
	else:
		break
print(ans)


from sys import exit
(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
decimals = set()
for i in a:
	if i in decimals:
		print(0)
		exit(0)
	decimals.add(i)
values = set(a)
new_values = set()
for value in list(values):
	new = value & x
	if new != value and new in values:
		print(1)
		exit(0)
	new_values.add(new)
if len(new_values) == len(values):
	print(-1)
else:
	print(2)


import sys, heapq
(n, x) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
res = dict().fromkeys(set(arr), 0)
for i in arr:
	res[i] += 1
can = False
for i in res:
	if res[i] >= 2:
		can = True
		break
if can:
	print(0)
else:
	res = dict().fromkeys([i for i in range(max(arr) + 1)])
	for i in res:
		res[i] = []
	for i in range(n):
		temp = set()
		now = arr[i]
		cnt = 0
		while True:
			added = False
			before = len(temp)
			temp.add(now)
			after = len(temp)
			if before == after:
				break
			heapq.heappush(res[now], cnt)
			now = now & x
			cnt += 1
	ans = 9876543210
	for i in res:
		if len(res[i]) >= 2:
			ans = min(ans, heapq.heappop(res[i]) + heapq.heappop(res[i]))
	print(ans if ans != 9876543210 else -1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 100001
c = [0] * 100001
for t in a:
	b[t] += 1
	if b[t] == 2:
		print(0)
		exit()
for t in a:
	y = x & t
	if b[y] == 1 and y != t:
		print(1)
		exit()
for t in a:
	y = x & t
	if c[y] == 1:
		print(2)
		exit()
	c[y] += 1
print(-1)


def bin_value(v, X):
	return v & X

def sol():
	(N, X) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	d = {}
	b = {}
	for (i, v) in enumerate(a):
		if v in d:
			return 0
		d[v] = i
	ans = 100
	for (i, v) in enumerate(a):
		binary = bin_value(v, X)
		if binary in d:
			index = d[binary]
			if i < index:
				ans = min(1, ans)
			elif i > index:
				ans = min(1, ans)
		if binary in b:
			index = b[binary]
			ans = min(2, ans)
		b[binary] = i
	return -1 if ans == 100 else ans
ans = sol()
print(ans)


def solve(x, a, n):
	set_a = set(a)
	if n != len(set_a):
		return 0
	list_ax = [aa & x for aa in a]
	set_ax = set(list_ax)
	if len(list_ax) == len(set_ax):
		return -1
	for (m, n) in zip(a, list_ax):
		if m != n and n in set_a:
			return 1
	return 2
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
pt = solve(x, a, n)
print(pt)


(n, x) = map(int, input().split())
a = sorted(map(int, input().split()))
s = set(a)
b = sorted(map(lambda u: u & x, a))
t = set(b)
if len(s) < len(a):
	print(0)
elif any(map(lambda u: u != u & x and u & x in s, a)):
	print(1)
elif len(t) < len(b):
	print(2)
else:
	print(-1)


(n, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = set(a)
if len(s) < n:
	print(0)
else:
	c = set()
	k = 0
	for i in range(n):
		if a[i] & x != a[i]:
			c.add(a[i] & x)
			k += 1
	if len(s | c) < len(s) + len(c):
		print(1)
	elif len(c) < k:
		print(2)
	else:
		print(-1)


import sys
[N, X] = [int(c) for c in input().split()]
arr = []
line = [int(c) for c in input().split()]
booarr = [0] * (10 ** 5 + 1)
booarr2 = [[] for c in range(10 ** 5 + 1)]
for c in range(N):
	a = line[c]
	arr.append(a)
	if booarr[a] == 0:
		booarr[a] = -1
	else:
		print(0)
		sys.exit()
for c in range(N):
	if arr[c] & X != arr[c]:
		if booarr[arr[c] & X] == -1:
			print(1)
			sys.exit()
		else:
			booarr2[arr[c] & X].append(c)
for c in range(N):
	for d in booarr2[arr[c] & X]:
		if d != c:
			print(2)
			sys.exit()
print(-1)


(n, x) = map(int, input().split())
ex = -1
a = list(input().split())
a.sort()
c = []
for i in range(n):
	if i < n - 1:
		if a[i] == a[i + 1]:
			ex = 0
	a[i] = int(a[i])
	b = a[i] & x
	c.append([b, 0])
	if b == a[i]:
		c[i][1] = 1
	a[i] = str(a[i])
c.sort()
for i in range(n):
	if i < n - 1:
		if c[i][0] == c[i + 1][0]:
			if (c[i][1] == 1 or c[i + 1][1] == 1) and ex != 0:
				ex = 1
			elif ex == -1:
				ex = 2
print(ex)


(n, x) = map(int, input().split())
check = 0
a = set([int(i) for i in input().split()])
if len(a) != n:
	check = 0
else:
	b = set()
	check = -1
	for i in a:
		b.add(i & x)
		if i != i & x and i & x in a:
			check = 1
	if len(b) != n and check == -1:
		check = 2
print(check)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 100001
for x in a:
	b[x] += 1
for x in b:
	if x > 1:
		print(0)
		exit(0)
c = [0] * 100001
for i in range(len(b)):
	if b[i] > 0:
		if i != i & m and b[i & m] > 0:
			print(1)
			exit(0)
		c[i & m] += 1
for x in c:
	if x > 1:
		print(2)
		exit(0)
print(-1)


(n, x) = map(int, input().split())
li = list(map(int, input().split()))
li2 = li[:]
for i in range(n):
	li2[i] &= x
if len(set(li)) < n:
	print(0)
elif len(set(li2)) == n:
	print(-1)
else:
	counter = False
	new_li = set(li)
	for i in new_li:
		if i != i & x and i & x in new_li:
			print(1)
			counter = True
			break
	if not counter:
		print(2)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
vis = {}
for i in range(n):
	vis.setdefault(a[i], 0)
	vis[a[i]] += 1
if max(vis.values()) > 1:
	print(0)
else:
	res = filter(lambda t: vis.get(t & x) and vis[t & x] > 0 and (t & x != t), a)
	tt = list(res)
	if tt:
		print(1)
	else:
		a = map(lambda t: t & x, a)
		if len(set(a)) < n:
			print(2)
		else:
			print(-1)


(n, x) = map(int, input().split())
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
if any((y >= 2 for y in c.values())):
	print(0)
	exit(0)
nc = set(filter(lambda y: y & x == y, c.keys()))
import itertools
cm = collections.Counter((y & x for y in itertools.filterfalse(lambda y: y & x == y, c.keys())))
if any((y in cm for y in nc)):
	print(1)
	exit(0)
if any((y >= 2 for y in cm.values())):
	print(2)
	exit(0)
print(-1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
s = set(l)
if len(s) != n:
	print(0)
	exit()
for x in l:
	d[x] = 1
ma = 4
for x in l:
	if x & m != x:
		if d.get(x & m, 0) == 0:
			d[x & m] = 2
		else:
			ma = min(ma, d[x & m])
if ma == 4:
	print(-1)
else:
	print(ma)


def solve(n, x, l):
	s = set()
	for i in l:
		if i in s:
			return 0
		else:
			s.add(i)
	for i in l:
		if i & x != i:
			if i & x in s:
				return 1
	s = set()
	for i in l:
		if i & x in s:
			return 2
		else:
			s.add(i & x)
	return -1
(n, x) = [int(i) for i in input().split(' ')]
l = [int(i) for i in input().split(' ')]
ans = solve(n, x, l)
print(ans)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for i in range(100005)]
vis = [0 for j in range(100005)]
flag = 0
tt = 0
for k in a:
	b[k] += 1
	if b[k] > 1:
		flag = 1
		break
if flag:
	print(0)
else:
	for k in a:
		t = k & x
		if b[t] and k != t:
			flag = 1
			break
		vis[t] += 1
		if vis[t] > 1:
			tt = 1
	if flag:
		print(1)
	elif tt:
		print(2)
	else:
		print(-1)


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		(n, x) = map(int, input().strip().split())
		a = list(map(int, input().strip().split()))
		ax = [ai & x for ai in a]

		def check(h):
			for (key, cnt) in h.items():
				if cnt > 1:
					return True
			return False
		ha = Counter()
		for e in a:
			ha[e] += 1
		if check(ha):
			print('0')
			return
		hx = Counter()
		for e in ax:
			hx[e] += 1
		for e in a:
			if e & x == e and hx[e] > 1:
				print('1')
				return
			if e & x != e and hx[e] > 0:
				print('1')
				return
		if check(hx):
			print('2')
			return
		print('-1')
solver()()


(n, x) = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
flag = 0
for i in b:
	if d.get(i):
		flag = 1
		break
	else:
		d[i] = 1
if flag:
	print(0)
else:
	flag = 0
	c = set()
	for i in b:
		a = i & x
		c.add(a)
		if d.get(a) and a != i:
			flag = 1
			break
	if flag:
		print(1)
	elif len(c) < n and flag == 0:
		print(2)
	else:
		print(-1)


from collections import defaultdict
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
t = defaultdict(int)
for i in a:
	t[i] += 1
for (u, v) in t.items():
	if v >= 2:
		print('0')
		exit(0)
for i in a:
	k = i & x
	if k != i and t[k] >= 1:
		print('1')
		exit(0)
for i in range(n):
	a[i] = a[i] & x
s = defaultdict(int)
for i in a:
	s[i] += 1
for (u, v) in s.items():
	if v >= 2:
		print('2')
		exit(0)
print('-1')


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, x) = rint()
a = list(rint())
a_dict = dict()
for i in range(n):
	if a[i] not in a_dict:
		a_dict[a[i]] = 1
	else:
		a_dict[a[i]] += 1
if n > len(a_dict):
	print('0')
	return
for i in range(n):
	if a[i] & x in a_dict:
		if a[i] & x == a[i]:
			if a_dict[a[i] & x] >= 2:
				print('1')
				return
		else:
			print('1')
			return
ax = [a[i] & x for i in range(n)]
ax_set = set(ax)
if n > len(ax_set):
	print('2')
else:
	print('-1')


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
s = set()
ans = -1
for i in l:
	if (1, i) in s:
		ans = 0
	elif (1, i & x) in s or (2, i) in s:
		if ans == 0:
			pass
		else:
			ans = 1
	elif (2, i & x) in s:
		if ans == 0 or ans == 1:
			pass
		else:
			ans = 2
	s.add((1, i))
	s.add((2, i & x))
print(ans)


from collections import Counter

def main():
	(n, x) = map(int, input().split())
	aa = set(map(int, input().split()))
	if len(aa) < n:
		print(0)
		return
	cc = Counter((a & x for a in aa if a & x != a))
	(bb, cc) = (set(cc.keys()), list(cc.most_common(1)) + [(0, 0)])
	print(1 if aa & bb else 2 if cc[0][1] > 1 else -1)
main()


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().split())
z = set(map(int, stdin.readline().split()))
if len(z) != a:
	stdout.write('0')
	exit()
r = set()
for i in z:
	if i & b in z and i & b != i:
		stdout.write('1')
		exit()
	r.add(i & b)
if len(r) != a:
	stdout.write('2')
	exit()
stdout.write('-1')


from sys import stdin
(n, x) = map(int, stdin.readline().split())
a = [int(y) for y in stdin.readline().split()]
a.sort()
a_set = set()
b_set = set()
ans = 10
for ax in a:
	y = ax & x
	if ax in a_set:
		ans = min(ans, 0)
	if y in a_set:
		ans = min(ans, 1)
	if y in b_set:
		ans = min(ans, 2)
	a_set.add(ax)
	b_set.add(y)
if ans == 10:
	ans = -1
print(ans)


import sys
input = sys.stdin.readline

def prog():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	one = set()
	none = set()
	zero_found = 0
	one_found = 0
	two_found = 0
	for i in range(n):
		if a[i] in none:
			zero_found = 1
		if a[i] in one:
			one_found = 1
		if a[i] & x in none:
			one_found = 1
		if a[i] & x in one:
			two_found = 1
		none.add(a[i])
		one.add(a[i] & x)
	if zero_found:
		print(0)
	elif one_found:
		print(1)
	elif two_found:
		print(2)
	else:
		print(-1)
prog()


def _and():
	(n, x) = map(int, input().split())
	arr = [int(k) for k in input().split()]
	arr_set = set(arr)
	if len(arr_set) < n:
		return 0
	result = -1
	new_vals = set()
	for i in range(n):
		if arr[i] & x != arr[i] and arr[i] & x in arr_set:
			return 1
		new_vals.add(arr[i] & x)
	if len(new_vals) != len(arr_set):
		return 2
	return result
print(_and())


(n, x) = map(int, input().split())
da = {}
db = {}
a = list(map(int, input().split()))
ans = 3
for i in a:
	if i in da:
		ans = 0
		da[i] += 1
	else:
		da[i] = 1
	tmp = i & x
	if tmp == i:
		continue
	if tmp in db:
		ans = min(ans, 2)
		db[tmp] += 1
	else:
		db[tmp] = 1
for i in db.keys():
	if i in da:
		ans = min(ans, 1)
if ans == 3:
	print('-1')
else:
	print(ans)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
f = [0] * 100010
for i in arr:
	f[i] += 1
for i in range(100010):
	if f[i] > 1:
		print(0)
		exit()
t = False
for i in range(n):
	xx = arr[i] & x
	f[xx] += 1
	f[arr[i]] -= 1
	if f[xx] > 1:
		print(1)
		exit()
	f[arr[i]] += 1
	f[xx] -= 1
for i in range(100010):
	if f[i] > 0:
		xx = i
		f[i] -= 1
		zz = x & xx
		f[zz] += 1
		if f[zz] > 1:
			print(2)
			exit()
print(-1)


def getUsefulWeight(coef, uw):
	if coef == 1:
		print(-1)
		return
	uw += uw / (coef - 1)
	return uw
(n, x) = list(map(int, input().strip().split(' ')))
a = list(map(int, input().strip().split(' ')))
d = {}
ret = 3
for y in a:
	val = y & x
	if y in d:
		newc = d[y]
		if ret > newc:
			ret = newc
	if val in d:
		newc = d[val] + 1
		if ret > newc:
			ret = newc
	d[y] = 0
	if val not in d:
		d[val] = 1
if ret == 3:
	print('-1')
else:
	print(ret)


import sys
from collections import Counter
(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
arr2 = list(map(lambda a: a & x, arr))
sa = Counter(arr)
sa2 = Counter(arr2)
for i in arr:
	if sa[i] >= 2:
		print(0)
		sys.exit(0)
for i in arr:
	if sa2[i] >= 2 if i & x == i else i in sa2:
		print(1)
		sys.exit(0)
for i in sa2:
	if sa2[i] >= 2:
		print(2)
		sys.exit(0)
print(-1)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = set()
c = set()
q = False
for i in a:
	if i in b:
		print(0)
		exit()
	b.add(i)
for i in a:
	k = i & x
	if k != i and k in b:
		print(1)
		exit()
	if k in c:
		q = True
	c.add(k)
if q:
	print(2)
else:
	print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a1 = set(a)
if len(a1) < n:
	print(0)
else:
	a2 = [i & x for i in a if i & x != i]
	if set(a2) & a1:
		print(1)
	elif len(set(a2)) < len(a2):
		print(2)
	else:
		print(-1)


(n, x) = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
sa = set(a)
if len(sa) < n:
	print(0)
else:
	la = [v & x for v in a if v & x != v]
	if set(la) & sa:
		print(1)
	elif len(set(la)) < len(la):
		print(2)
	else:
		print(-1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
sa = set(a)
if len(a) > len(sa):
	print(0)
else:
	b = [y & x for y in a if y != y & x]
	for y in b:
		if y in sa:
			print(1)
			exit()
	sb = set(b)
	if len(b) > len(sb):
		print(2)
	else:
		print(-1)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i] & x for i in range(n)]
da = dict()
db = dict()
flag = -1
for i in a:
	if i not in da:
		da[i] = 1
	else:
		print(0)
		exit(0)
for i in range(n):
	if b[i] in da and a[i] != b[i]:
		print(1)
		exit(0)
	if b[i] not in db:
		db[b[i]] = 1
	else:
		flag = 2
print(flag)


(n, x) = map(int, input().split())
u = list(map(int, input().split()))
s = set()
for i in range(n):
	if u[i] not in s:
		s.add(u[i])
	else:
		print(0)
		exit()
s1 = set()
ans = -1
for i in range(n):
	k = u[i] & x
	if k in s1:
		ans = 2
	else:
		s1.add(k)
	if u[i] != k and k in s:
		ans = 1
		break
print(ans)


q = set()
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
q.add(a[0] & x)
mi = 10
for i in range(1, n):
	if a[i] == a[i - 1]:
		mi = min(mi, 0)
	if a[i] in q:
		mi = min(mi, 1)
	if a[i] & x in q:
		mi = min(mi, 2)
	q.add(a[i] & x)
if mi == 10:
	print(-1)
else:
	print(mi)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
cnt = [0] * 100001
ans = 3
for i in range(n):
	cnt[arr[i]] += 1
	if cnt[arr[i]] > 1:
		print(0)
		exit()
ans = 9999999999
stp = [0] * 100001
for i in range(n):
	ct = 0
	while 1:
		y = arr[i] & x
		if y != arr[i]:
			ct += 1
			if cnt[y] == 1 or stp[y] > 0:
				ans = min(ans, ct + stp[y])
				break
			else:
				stp[y] += 1
			arr[i] = y
		else:
			break
if ans == 9999999999:
	print(-1)
else:
	print(ans)


(n, x) = map(int, input().split())
a = [int(i) for i in input().split()]
dictionary = {}
a.sort()
flag = 0
for (ind, a_i) in enumerate(a):
	if a_i not in dictionary:
		dictionary[a_i] = ind
	else:
		flag = 1
		break
if flag == 1:
	print(0)
else:
	flag = 0
	for (ind, a_i) in enumerate(a):
		if a_i & x in dictionary and dictionary[a_i & x] != ind:
			flag = 1
			break
	if flag == 1:
		print(1)
	else:
		flag = 0
		for ind in range(n):
			a[ind] &= x
		a.sort()
		flag = 0
		for (ind, a_i) in enumerate(a[1:]):
			if a_i == a[ind]:
				flag = 1
				break
		print(2 if flag == 1 else -1)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
d = set()
for i in a:
	if i in d:
		print(0)
		exit()
	d.add(i)
for i in a:
	if i & x in d and i != i & x:
		print(1)
		exit()
b = a
for i in range(n):
	b[i] &= x
e = set()
for i in b:
	if i in e:
		print(2)
		exit()
	e.add(i)
print(-1)


(n, x) = map(int, input().split(' '))
ais = list(map(int, input().split(' ')))
d = dict()
min_ops = 3
for ai in ais:
	if ai in d:
		min_ops = min(min_ops, d[ai])
	elif ai & x in d:
		min_ops = min(min_ops, d[ai & x] + 1)
	d[ai] = 0
	if ai & x not in d:
		d[ai & x] = 1
print(min_ops if min_ops <= 2 else -1)


from collections import defaultdict as dd
(n, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
dic = dd(int)
dic1 = dd(int)
flag = 0
for i in a:
	dic[i] += 1
	if dic[i] > 1:
		flag = 1
if flag == 1:
	print(0)
else:
	flag = -1
	for i in range(len(a)):
		num = a[i] & x
		if num == a[i] and dic[num] > 1:
			flag = 1
			break
		elif dic[num] != 0 and num != a[i]:
			flag = 1
			break
		dic1[num] += 1
		if dic1[num] > 1 and num != a[i]:
			flag = 2
	print(flag)


import bisect
(n, x) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0] * n
a.sort()
f = True
ans = 0
for i in range(n - 1):
	if a[i] == a[i + 1]:
		print(0)
		f = False
		break
if f:
	for i in range(n):
		now = x & a[i]
		b[i] = now
		index = bisect.bisect(a, now)
		if a[index - 1] == now and now != a[i]:
			print(1)
			f = False
			break
	b.sort()
	if f:
		for i in range(n - 1):
			if b[i] == b[i + 1]:
				print(2)
				f = False
				break
		if f:
			print(-1)


def main():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	uniq = set(a)
	m = len(uniq)
	ans = -1
	if m != n:
		ans = 0
	else:
		bitwise = set()
		for i in a:
			t = i & x
			if t in uniq and t != i:
				ans = 1
				break
			else:
				bitwise.add(t)
	if ans == -1 and len(bitwise) != n:
		ans = 2
	print(ans)
main()


(n, m) = map(int, input().split())
s = input().split()
a = dict()
f = 3
if len(set(s)) < n:
	print(0)
else:
	for i in range(n):
		if int(s[i]) & m not in a:
			a[int(s[i]) & m] = int(s[i])
		elif int(s[i]) == a[int(s[i]) & m] & m or int(s[i]) & m == a[int(s[i]) & m]:
			f = 1
			break
		else:
			f = min(f, 2)
	if f == 3:
		f = -1
	print(f)


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = int(100000.0 + 1)
bull_1 = [0] * cnt
bull_2 = [0] * cnt
for i in range(n):
	if bull_1[a[i]] == 1:
		print(0)
		exit()
	bull_1[a[i]] = 1
for i in range(n):
	if bull_1[a[i] & x] == 1 and a[i] != a[i] & x:
		print(1)
		exit()
for i in range(n):
	if bull_2[a[i] & x] == 1:
		print(2)
		exit()
	bull_2[a[i] & x] = 1
print(-1)


from sys import stdin, stdout

def main():
	io = Stdio()
	n = io.nextInt()
	x = io.nextInt()
	a = [io.nextInt() for i in range(n)]
	a.sort()
	for i in range(1, n):
		if a[i - 1] == a[i]:
			io.println(0)
			return
	b = [a[i] & x for i in range(n)]
	for i in range(n):
		posInA = binarySearch(a, b[i])
		if posInA != -1 and posInA != i:
			io.println(1)
			return
	b.sort()
	for i in range(n):
		if b[i - 1] == b[i]:
			io.println(2)
			return
	io.println(-1)

def binarySearch(a, x):
	start = 0
	end = len(a) - 1
	while start < end:
		mid = (start + end) // 2
		if a[mid] == x:
			return mid
		if a[mid] > x:
			end = mid - 1
		elif a[mid] < x:
			start = mid + 1
	if a[start] == x:
		return start
	return -1

class Stdio:
	index = 0
	line = []

	def readline(self):
		return stdin.readline().strip().split()

	def next(self):
		while self.index >= len(self.line):
			self.line = self.readline()
			self.index = 0
		token = self.line[self.index]
		self.index += 1
		return token

	def nextInt(self):
		return int(self.next())

	def nextFloat(self):
		return float(self.next())

	def nextChar(self):
		return chr(self.next())

	def print(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))

	def println(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))
		stdout.write('\n')
main()


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
s1 = set(a)
s2 = []
if len(s1) < len(a):
	print(0)
	exit()
o = -1
for i in s1:
	w = i & x
	if w != i:
		s2.append(w)
if len(s2) > len(set(s2)):
	o = 2
if len(set(s2) & s1) > 0:
	o = 1
print(o)