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 . 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)}
type PH' a = (a, [PH' a])
merge' :: PH' a -> PH' a -> PH' a
merge' u@(x, us) v@(y, vs) = if y > x then (x, v : us) else (y, u : vs)
isEmpty = isNothing . unPH
empty = PH Nothing
insert = merge . PH . Just . flip (,) []
merge (PH Nothing) v = v
merge u (PH Nothing) = u
merge (PH (Just u')) (PH (Just v')) = PH . Just $ merge' u' v'
uncons = \u -> case u of
  (PH (Just (x, us))) -> (,) x .  foldl merge empty . (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 xs = foldl merge empty . map singleton $ xs

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