import Control.Applicative

solve :: Integer -> [[Integer]] -> Integer
solve c [] = c
solve c ([a,b]:ablist) = solve (c+e) ablist
  where d = a+c
        e = head [b*x-d|x<-[d`div`b..],b*x>=d]

main = do
  _ <- read <$> getLine :: IO Integer
  ablist <- reverse.map (map read.words).lines <$> getContents :: IO [[Integer]]
  print $ solve 0 ablist
