n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

h = Array.new(41, 0)
a.each {|x| x.bit_length.times {|i| h[i] += x[i]} }

b = true
ans = 0
40.downto(0) do |i|
    x = h[i] > n/2 ? 0 : 1
    
    if b
        if k[i] == x
            ans |= x << i
        elsif k[i] < x
        else
            b = false
        end
    else
        ans |= x << i
    end
end
#p ans
p a.inject(0){|r, v| r + (v ^ ans)}