import Data.List

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

solve :: Int -> [Int] -> Int
solve k l = sum . take k $ sortBy (flip compare) l