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

t = 50.times.map{|i| [
  a.map{|a|  a & (1<<i)}.inject(&:+),
  a.map{|a| ~a & (1<<i)}.inject(&:+),
]}


puts 50.times.map {|i|
  next 0 if k[i] == 0

  sum = 0
  sum += (i+1..49).map{|i| t[i][k[i]]}.inject(0,&:+)
  sum += t[i][0]
  sum += (0..i-1).map{|i| t[i].max}.inject(0,&:+)

  sum
}.max
