{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [n,m] <- map read.words <$> getLine :: IO [Int]
    xs <- U.unfoldrN n parseInt <$> C.getLine
    print $ solve n m xs

solve :: Int -> Int -> U.Vector Int -> Int
solve n m xs = runST $ do
    h <- _HHMnewHeap n
    U.forM_ xs $ \x -> do
        _HHMinsertM x h
    U.forM_ (U.generate m id) $ \_ -> do
        x <- _HHMunsafeMaxViewM h
        _HHMunsafeDeleteMaxM h
        _HHMinsertM (quot x 2) h
    let MaxHeapM _ mh = h
    u <- U.unsafeFreeze mh
    return $ U.sum u

-------------------------------------------------------------------------------

data MaxHeapM m a = MaxHeapM (MutVar m Int) (UM.MVector m a)

_HHMnewHeap :: (PrimMonad m, U.Unbox a) => Int -> m (MaxHeapM (PrimState m) a)
_HHMnewHeap limitSize = MaxHeapM `liftM` newMutVar 0 `ap` UM.new limitSize

_HHMgetHeapSize :: (PrimMonad m) => MaxHeapM (PrimState m) a -> m Int
_HHMgetHeapSize (MaxHeapM ref _) = readMutVar ref
{-# INLINE _HHMgetHeapSize #-}

_HHMinsertM :: (PrimMonad m, U.Unbox a, Ord a)
    => a -> MaxHeapM (PrimState m) a -> m ()
_HHMinsertM x heap@(MaxHeapM ref vec) = do
    size <- _HHMgetHeapSize heap
    modifyMutVar' ref (+1)
    flip fix size $ \loop !i ->
        if i == 0
        then UM.unsafeWrite vec 0 x
        else do
            let !parent = (i - 1) `unsafeShiftR` 1
            p <- UM.unsafeRead vec parent
            if p >= x
            then UM.unsafeWrite vec i x
            else do
                UM.unsafeWrite vec i p
                loop parent
{-# INLINE _HHMinsertM #-}

_HHMunsafeDeleteMaxM :: (PrimMonad m, U.Unbox a, Ord a)
                 => MaxHeapM (PrimState m) a -> m ()
_HHMunsafeDeleteMaxM (MaxHeapM ref vec) = do
    modifyMutVar' ref (subtract 1)
    size <- readMutVar ref
    x <- UM.unsafeRead vec size
    flip fix 0 $ \loop !i -> do
        let !l = unsafeShiftL i 1 .|. 1
        if size <= l
        then UM.unsafeWrite vec i x
        else do
            let !r = l + 1
            childL <- UM.unsafeRead vec l
            childR <- UM.unsafeRead vec r
            if r < size && childR > childL
            then if x >= childR
                 then UM.unsafeWrite vec i x
                 else do
                     UM.unsafeWrite vec i childR
                     loop r
            else if x >= childL
                 then UM.unsafeWrite vec i x
                 else do
                     UM.unsafeWrite vec i childL
                     loop l
{-# INLINE _HHMunsafeDeleteMaxM #-}

_HHMunsafeMaxViewM :: (PrimMonad m, U.Unbox a) => MaxHeapM (PrimState m) a -> m a
_HHMunsafeMaxViewM (MaxHeapM _ vec) = UM.unsafeRead vec 0
{-# INLINE _HHMunsafeMaxViewM #-}

_HHMMaxViewM :: (PrimMonad m, U.Unbox a) => MaxHeapM (PrimState m) a -> m (Maybe a)
_HHMMaxViewM heap = do
    size <- _HHMgetHeapSize heap
    if size > 0
    then Just `liftM` _HHMunsafeMaxViewM heap
    else return Nothing
{-# INLINE _HHMMaxViewM #-}

_HHMdeleteFindMaxM :: (PrimMonad m, U.Unbox a, Ord a)
    => MaxHeapM (PrimState m) a -> m (Maybe a)
_HHMdeleteFindMaxM heap = do
    size <- _HHMgetHeapSize heap
    if size > 0
    then liftM2 ((Just.).const) (_HHMunsafeMaxViewM heap) (_HHMunsafeDeleteMaxM heap)
    else return Nothing
{-# INLINE _HHMdeleteFindMaxM #-}

_HHMclearMaxHeapM :: (PrimMonad m) => MaxHeapM (PrimState m) a -> m ()
_HHMclearMaxHeapM (MaxHeapM ref _) = writeMutVar ref 0
{-# INLINE _HHMclearMaxHeapM #-}

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)