N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

digits = 1
ans = 0
x = 0
while 2 ** (digits + 1) <= K
	digits += 1
end

digits.downto(0) do |i|
	s = 1 << i
	cnt = A.select{|n| n & s > 0}.size
	if cnt >= N / 2 || x + 2 ** i > K
		ans += (2 ** i) * cnt
	else
		x += 2 ** i
		ans += (2 ** i) * (N - cnt) 
	end
end

puts ans