{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

solve :: Int -> [(Int, Int)] -> Int
solve n abs = go 0 abs
  where
    go !k []           = k
    go !k ((a, b):abs) = go (k + (an - a')) abs
      where
        a' = a + k
        an | a' `mod` b == 0 = a'
           | otherwise      = (a' `div` b + 1) * b

main :: IO ()
main = do
    n <- readLn :: IO Int
    abs <- replicateM n $ do
        [a, b] <- fmap readi . B.words <$> B.getLine
        return (a, b)
    print $ solve n (reverse abs)