import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = BC.getContents >>= print . solve . map (fst . fromJust . BC.readInt) . BC.words

solve (n:as) = solve2 0 $ reverse $ drop n $ sort as

solve2 cnt [] = cnt
solve2 cnt (_:a:as) = solve2 (cnt + a) as