-- Question B

import Data.List
import Control.Applicative
import Control.Monad

main = do
  [a, b] <- map read . words <$> getLine
  xs <- (map read . words) <$> getLine 
  putStrLn $ show ( check (nara xs) b)

nara :: [Int] -> [Int]
nara xs = reverse ( sort xs )   

check :: [Int] -> Int -> Int
check xs b = sum ( take b xs)
