def read_data(): N = int(input()) xy = [] for n in range(N): x, y = map(int, input().split()) xy.append((x, y)) return N, xy def gcd_ext(m, n): x, y, u, v = 1, 0, 0, 1 while n: k, m = divmod(m, n) m, n = n, m x, y, u, v = u, v, x - u * k, y - v * k return m, x, y def solve2(x1, y1, x2, y2): gcd, a, b = gcd_ext(y1, y2) lcm = y1 * y2 // gcd k, r = divmod(x1 - x2, gcd) if r != 0: return -1, lcm z = (x1 - k * a * y1) % lcm return z, lcm def solve(N, xy): x0, y0 = xy[0] if N == 1: return x0 if x0 else y0 mod = 10 ** 9 + 7 for x1, y1 in xy[1:]: x0, y0 = solve2(x0, y0, x1, y1) if x0 == -1: return -1 return x0 % mod if x0 else y0 % mod N, xy = read_data() print(solve(N, xy))