import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.List
main = print.solve.map(fst.fromJust.B.readInt).B.words=<<B.getContents
solve (n:k:xs) = sum . take k . sortBy (flip compare) $ xs