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

getI :: ByteString -> Maybe (Int, ByteString)
getI = fmap (second BSC8.tail) . BSC8.readInt
getAB :: IO (Int, Int)
getAB = (\vec -> (vec UV.! 0, vec UV.! 1)) . UV.unfoldrN 2 getI <$> BSC8.getLine

getIL :: IO [Int]
getIL = unfoldr f <$> BSC8.getLine
  where
    -- f :: ByteString -> Maybe (Int, ByteString)
    f s = do
      (n, s') <- BSC8.readInt s
      return (n, BSC8.dropWhile isSpace s')

main :: IO ()
main = do
  (_, k) <- getAB
  ps <- getIL
  print $ sum . take k . sort $ ps
