from functools import * def egcd(a, b): x, y, u, v = 0, 1, 1, 0 while a != 0: q, r = b // a, b % a m, n = x - u * q, y - v * q b, a, x, y, u, v = a, r, u, v, m, n gcd = b return gcd, x, y def lcm(a, b): from fractions import gcd return a // gcd(a, b) * b def gcrt(congs): def fn(cong, prod): a, n = cong m = prod // n g, x, _ = egcd(m, n) return m // g * x * a def crt(a, b): N = a[1] * b[1] L = lcm(a[1], b[1]) return (fn(a, N) + fn(b, N)) % L, L return reduce(crt, congs) def main(): N = int(raw_input()) congs = [tuple([int(x) for x in raw_input().split(" ")]) for _ in range(N)] ans, mod = gcrt(congs) if ans == 0: ans = mod if any(ans % m != a for a, m in congs): print(-1) else: print(ans % (10**9 + 7)) if __name__ == "__main__": main()