import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLine >>= main'
    where
        main' [n, m] = readContents n >>= print . solve m

solve :: Int -> [[Int]] -> Int
solve m = count m 0 . sortBy cmpf 
    where
        cmpf = comparing head
        
        count 0 acc _ = acc
        count n acc ([a, b] : xs)
            | n < b = acc + n * a
            | otherwise = count (n - b) (acc + a * b) xs

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine