import math

n = int(input())
current_a = 0
current_m = 1
valid = True

for _ in range(n):
    x, y = map(int, input().split())
    if not valid:
        continue  # Skip processing once invalid
    
    d = x - current_a
    g = math.gcd(current_m, y)
    
    if d % g != 0:
        valid = False
        continue
    
    # Compute the new parameters
    m1 = current_m // g
    y1 = y // g
    d_div_g = d // g
    
    # Find the modular inverse of m1 mod y1
    try:
        inv = pow(m1, -1, y1)
    except ValueError:
        valid = False
        continue
    
    k0 = (d_div_g * inv) % y1
    new_a = current_a + current_m * k0
    new_m = current_m * y // g
    
    current_a = new_a
    current_m = new_m

if not valid:
    print(-1)
else:
    if current_a == 0:
        ans = current_m
    else:
        ans = current_a
    mod = 10**9 + 7
    print(ans % mod)