import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Maybe (isNothing)

main :: IO ()
main = do
  (n : m : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . negate . sum . toList . f m . fromList . map negate $ as

f :: Int -> PH Int -> PH Int
f 0 h = h
f m h = let (x, h') = uncons h in f (pred m) . insert (x `quot` 2) $ h'

newtype PH a = PH {unPH :: Maybe (PH' a)}
data PH' a = PH' a [PH' a]
merge' :: Ord a => PH' a -> PH' a -> PH' a
merge' u@(PH' x us) v@(PH' y vs) = if y > x then PH' x (v : us) else PH' y (u : vs)
isEmpty :: PH a -> Bool
isEmpty = isNothing . unPH
empty :: PH a
empty = PH Nothing
insert :: Ord a => a -> PH a -> PH a
insert = merge . PH . Just . flip PH' []
singleton :: Ord a => a -> PH a
singleton x = insert x empty
merge :: Ord a => PH a -> PH a -> PH a
merge (PH Nothing) v = v
merge u (PH Nothing) = u
merge (PH (Just u')) (PH (Just v')) = PH . Just $ merge' u' v'
uncons :: Ord a => PH a -> (a, PH a)
uncons = \u -> case u of
  (PH (Just (PH' x us))) -> (,) x .  foldl merge empty . map (PH . Just) . ((maybe id (:)) <$> fst <*> snd) . foldl step (Nothing, []) $ us
  where
    step (Nothing, vs) u = (Just u, vs)
    step (Just v, vs) u = (Nothing, merge' v u : vs)
fromList :: Ord a => [a] -> PH a
fromList xs = foldl merge empty . map singleton $ xs
toList :: Ord a => PH a -> [a]
toList (PH Nothing) = []
toList u = let (x, u') = uncons u in x : toList u'

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
