module Main where import qualified Data.ByteString.Char8 as BS import Data.Char import Data.String import Data.List import Data.Maybe import Data.Ord import Control.Monad main :: IO () main = do [n, k] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine an <- sortOn Down . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine let r = maximum $ [ sum $ take i an | i <- [1 .. k] ] print r