import Data.List (sortBy)

main:: IO ()
main = do
    [_,k] <- (map read . words) <$> getLine
    ls <- (map read . words) <$> getLine
    print $ solve k ls

-- |
--
-- >>> solve 3 [1,2,3,4,5]
-- 12
solve :: Int -> [Int] -> Int
solve k ls = sum $ take k $ rSort ls

rSort :: (Ord a) => [a] -> [a]
rSort = sortBy (flip compare)
