import Data.List
import Data.Ord

main = interact $ unlines . map (show . princess_marriage) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nm:xs) = (m, map ((\[d,p]->(d,p)). map read . words) dps) : read' xs'
   where
    [n,m] = map read (words nm)
    (dps,xs') = splitAt (fromInteger n) xs

princess_marriage (m,dps) = sum . map (uncurry (*)) . hire m . reverse . sortBy (comparing snd) $ dps
 where
  hire _ [] = []
  hire m' ((d,p):dps') = if m' <= d then (d-m',p):dps' else hire (m'-d) dps'