# https://atcoder.jp/contests/abc117/tasks/abc117_d
=begin
3 7
1 6 3

14

4 9
7 4 0 3

46

1 0
1000000000000

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

upper_bit = K.to_s(2)
upper_bit_length = upper_bit.length
max_bit_length = A.max.to_s(2).length

zero_str = (0..40).to_a.each_with_object([]) { |i, obj| obj << '0' * i}.reverse.freeze
zero_fill_strA = A.map { |i| "#{zero_str[i.to_s(2).size]}#{i.to_s(2)}" }

zero_fill_upper_bit =  "#{zero_str[upper_bit.size]}#{upper_bit}"

one = '1'
zero = '0'
mask = ''
already_min = false
0.step(39) do |digest|
  if zero_fill_strA.count { |str| str[digest] == one } * 2 >= N
    already_min = true if zero_fill_upper_bit[digest] == one
    mask << zero
  else
    if already_min || zero_fill_upper_bit[digest] == one
      mask << one
    else
      mask << zero
    end
  end
end
mask = mask.to_i(2)
ans = 0
A.each { |i| ans += (i ^ mask) }
p ans