n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
left=0
right=1000000001
while true
  mid=(left+right)/2
  c=0
  a.each do |aa|
    while aa>mid
      aa/=2
      c+=1
    end
  end
  # p [mid,left,right,c]
  if c==m||mid==0
    ans=0
    a.each do |aa|
      while aa>mid
        aa/=2
      end
      ans+=aa
    end
    break
  elsif right-left==1
    # ここには入力例4のパターンを入れたい
    puts "-1"
    exit
  elsif c>m
    left=mid
  else
    right=mid
  end
end
puts ans

