main = do
  getLine
  tas <- map (map read . words) . lines <$> getContents
  print (report tas)

report = sum . foldl1 asum

asum [at,aa] [t,a] = let n = max (idiv at t) (idiv aa a) in [n*t, n*a]

idiv x y = ceiling $ (fromIntegral x) / (fromIntegral y)