qsort [] = []
qsort (n:xs) = qsort gteq ++ [n] ++ qsort lt
  where
    lt = [x| x <- xs, x < n]
    gteq = [x| x <- xs, x >= n]

main = do
  [_, k] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  print $ sum $ take k $ qsort (as::[Int])