def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a.unshift x  if x <= (a=b)[0]
    return a << x  if x >= a[-1]
    i = a.bsearch_index {|y| x <= (y.frozen? ? y: y[0])}
    b = a[i-=1]  if (b=a[i]).frozen? ? x<b: x<b[0]
  end  if b && b=a
  return a.insert(i+1, x)  if a.size-i < 9
  i > 9 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a)
  return a.shift  if !a[1]
  l,a = a,n  until (n=a[0]).frozen?
  if (r=a[1]).frozen?; l[0] = r if l && !a[2]; a.shift
  else a[0] = deq r; a[1] = r[0] if !r[1]; n end
end
N,M,*A = $<.read.split.map{|x| -x.to_i}
A.sort!
(-M).times { break if A[0]==0; enq A, -(-(deq A)/2) }
p A.flatten.inject(0,:-)