Scanf.scanf "%d" (fun n ->
    let ta = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun t a -> t, a)) in

    let rec loop i t a =
        if i = n then Printf.printf "%d\n" (t + a) else
            let t1, a1 = ta.(i) in

            let t2 = (t + t1 - 1) / t1 * t1 in
            let a2 = t2 / t1 * a1 in

            let a3 = (a + a1 - 1) / a1 * a1 in
            let t3 = a3 / a1 * t1 in

            if t2 >= t && a2 >= a then (
                if t3 >= t && a3 >= a then (
                    if t2 < t3 then loop (i + 1) t2 a2
                               else loop (i + 1) t3 a3
                ) else loop (i + 1) t2 a2
            ) else loop (i + 1) t3 a3
    in
    loop 1 (fst ta.(0)) (snd ta.(0))
)