import Data.List
import Data.Ord

solve :: Int -> [Int] -> Int
solve _ [] = 0
solve k (n:ns)
    | k > 0 = solve (k-1) ns
    | otherwise = sum (n:ns)

main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    ns <- sortBy (comparing Down) . map read . words <$> getLine :: IO [Int]
    print $ solve k ns