main :: IO ()
main  = do
    [n, k] <- map read . words <$> getLine
    xs <-  map read . words <$> getLine
    putStrLn $ show $ sum $ take k $ quicksort xs

quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = quicksort (filter (< x) xs) ++ [x] ++ quicksort (filter (>= x) xs)
    