import Control.Monad
main=do
    n<-readLn
    tas<-replicateM n $ map read.words<$>getLine::IO[[Int]]
    print.sum.foldl1 f $ tas

f [u,v] [t,a] = (\n->[t*n, a*n]) $ head [n|n<-[(u+v)`div`(t+a)..], t*n>=u, a*n>=v]

