import Data.List
--import Control.Monad

main = do
  [n, k] <- (map read . words) <$> getLine
  l <- (map read . words) <$> getLine
  putStrLn .show $ solve k l

solve:: Int -> [Int] -> Int
solve k l = foldl (+) 0 $ take k $reverse $ sort l