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 $ concat $ map (\x -> replicate (x !! 1) (x !! 0)) $ sortBy (\x y -> compare (x !! 0) (y !! 0)) a
