import Control.Arrow (second)
import Data.List (sort, scanl1)
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as UV
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString as BSC8



main :: IO ()
main = do
  let readInt = fmap (second BSC8.tail) . BSC8.readInt
  (n, k) <- (\vec -> (vec UV.! 0, vec UV.! 1)) . UV.unfoldrN 2 readInt <$> BSC8.getLine

  ps <- UV.unfoldrN n readInt <$> BSC8.getLine
  print $ sum $ take k $ sort $ UV.toList ps