main = getLine >> getContents >>= print . uncurry (+) . solve (1, 1) . map (map read . words) . lines

solve :: (Int, Int) -> [[Int]] -> (Int, Int)
solve (a, b) ([x, y] : zs) = solve (n * x, n * y) zs
    where
        n = max nx ny
        nx = ceiling $ (fromIntegral a) / (fromIntegral x)
        ny = ceiling $ (fromIntegral b) / (fromIntegral y)

solve ab _ = ab
