import Control.Applicative

func :: [Integer] -> [Integer] -> [Integer]
func (a:b:_) (x:y:_)
  | a < b = (ceiling ((fromIntegral b) / (fromIntegral y))*x):(ceiling ((fromIntegral b) / (fromIntegral y))*y):[]
  | a >= b = (ceiling ((fromIntegral a) / (fromIntegral x))*x):(ceiling ((fromIntegral a) / (fromIntegral x))*y):[]

main = do
  getLine
  dat <- map (map (read::String->Integer) . words) . lines <$> getContents

  print $ sum $ foldl func [1,1] dat
