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 = ceiling $ fromIntegral a / fromIntegral x
        ny = ceiling $ fromIntegral b / fromIntegral y
