{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE UndecidableInstances #-}

module Main where

import Control.Category hiding (id, (.))
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as BS
import Data.IORef
import Data.List as List
import Data.Maybe
import Data.Set as Set
import qualified Data.Vector.Unboxing as U
import qualified Data.Vector.Unboxing.Mutable as UM
import GHC.Generics

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readIntList :: BS.ByteString -> [Int]
readIntList = Prelude.map readInt . BS.words

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = readIntList <$> BS.getLine

-- data Point = Pt {-# UNPACK #-} !Int {-# UNPACK #-} !Int
--   deriving (Generic)
--   deriving (U.Unboxable) via U.Generics Point

-- ptX :: Point -> Int
-- ptX (Pt x y) = x

-- ptY :: Point -> Int
-- ptY (Pt x y) = y

data Item = Item
  { price :: {-# UNPACK #-} !Int,
    idx :: {-# UNPACK #-} !Int
  }
  deriving (Eq)

instance Ord Item where
  compare item0 item1 = compare (price item0) (price item1) <> compare (idx item0) (idx item1)

divideItem :: Item -> Item
divideItem Item {price = price, idx = idx} = Item {price = price `div` 2, idx = idx}

divideItems :: Set Item -> Set Item
divideItems s = Set.insert (divideItem . findMax $ s) . deleteMax $ s

sumItems :: Set Item -> Int
sumItems = sum . fmap price . toList

main :: IO ()
main = do
  [n, m] <- getIntList
  as <- getIntList
  let items0 = Set.fromList . fmap (\(idx, a) -> Item {price = a, idx = idx}) $ zip [0 ..] as
      items1 = List.foldl' (\items _ -> divideItems items) items0 [1 .. m]
  print . sumItems $ items1