module Main where

import Control.Applicative

main :: IO ()
main = do
  n <- getLine
  lst <- map (map (read::String->Int) . words) . lines <$> getContents
  print $ solve lst 0 0

solve :: [[Int]] -> Int -> Int -> Int
solve [] t a = t + a
solve ([t,a]:xs) u b
  | t < u || a < b = let
    (nt, na) = head . dropWhile (\(x,y)->x<u||y<b) $ iterate (\(x,y)->(x+t,y+a)) (t,a)
    in solve xs nt na
  | otherwise = solve xs t a
