module Main where

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

main :: IO ()
main = do
    [n, k] <- fmap read . words <$> getLine
    ls <- sortBy (flip compare) . fmap read . words <$> getLine
    let ans = sum $ take k ls
    print ans