import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B

main=do
    n<-readLn
    print=<<sum.take n.unfoldr f.sortBy(flip compare).unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine
f (a:b:r) = Just(b,r)