import Data.List

main :: IO ()
main = do
  [_,k] <- reads2List
  input <- reads2List :: IO [Int]
  print . sum . take k $ sortBy (flip compare) input


s2List :: Read a => String -> [a]
s2List = fmap read . words

reads2List :: Read a => IO [a]
reads2List = do
  s <- getLine
  return (s2List s)
