MOD=10**9+7
cnt=0; sum=0; prev=nil; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k = gsmi
a = gsmi.sort

if k==0
  putsend(a.inject(:+))
end
# 下からi桁目が1のもの
vote = Array.new(100,0)
n.times do |i|
  bin = a[i].to_s(2).reverse
  l = bin.length
  l.times do |j|
    if bin[j] == "1"
      vote[j] += 1
    end
  end
end

# 多数決から期待kを出す
ex_k = ""
bin = k.to_s(2)
l = bin.length
l.times do |i|
  if n/2 < vote[l-i-1]
    ex_k<<"0"
  else
    ex_k<<"1"
  end
end

# 期待kがkより大きい場合は補正する
real_k=""
l.times do |i|
  if bin[i]=="1"
    if ex_k[i]=="0"
      real_k<<ex_k[i..-1]
      break
    else
      real_k<<"1"
    end
  else
    real_k<<"0"
  end
end

# puts vote[0..30].to_s
# puts ex_k
# puts real_k

# sum
vote.size.times do |i|
  num =
    if i<l && real_k[l-i-1]=="1"
      n-vote[i]
    else
      vote[i]
    end
  sum += 2**i * num
  #puts sum
end

puts sum
