import Data.List


toInt :: (String -> Int)
toInt x = read x ::Int

getInts :: IO [Int]
getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y



solve :: Int -> [Int] -> Integer
solve k h = f0 k $ reverse (sort h)

f0 :: Int -> [Int] -> Integer
f0 0 [] = 0 :: Integer
f0 0 (h:hs) = toInteger h + f0 0 hs
f0 n [] = 0 :: Integer
f0 n (h:hs) = f0 (n-1) hs




main = do
  nk <- getInts
  h <- getInts
  let k = nk !! 1
  putStrLn $ show (solve k h)
