import Control.Monad
import Data.List

main = do
    [n, m] <- map read . words <$> getLine
    a <- map ( map read . words) <$> replicateM n getLine
    putStrLn $ show $ sum $ take m $ sort $ concat $ map (\a -> replicate (a !! 1) (a !! 0)) a
