import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:m:as)=foldr(\(k,v)s->truncate k*v+s)0.M.toList.f m.M.fromListWith(+).map(\a->(fromIntegral a,1))$as
f m q=foldr g q[1..m]
g _ q=M.insertWith(+)(0.5*fst(M.findMax q))1.M.updateMax(\v->if v<2 then Nothing else Just(v-1))$q