import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [_,k] <- map (read::String->Int) . words <$> getLine
  ls <- sortBy (flip compare) .map (read::String->Int) . words <$> getLine
  (print .sum .take k) ls