import Data.List
main = getLine >> getContents >>= print . uncurry (+) . foldl' ff (1, 1) . map (map read . words) . lines

ff :: (Int, Int) -> [Int] -> (Int, Int)
ff (a, b) [x, y] = (n * x, n * y)
    where
        n = max nx ny
        nx
            | a `mod` x == 0 = a `div` x
            | otherwise = a `div` x + 1
        ny
            | b `mod` y == 0 = b `div` y
            | otherwise = b `div` y + 1
