def ext_gcd(a, b): # ax + by = gcd(a, b) if b == 0: return (1, 0, a) x, y, g = ext_gcd(b, a % b) return (y, x - (a // b) * y, g) def inv_gcd(a, b): x, y, g = ext_gcd(a, b) return (g, x % b) # returns (x % lcm(M), lcm(M)), (x = R[i] (mod M[i])) def crt(R, M): N = len(R) r0 = 0 m0 = 1 for i in range(N): r1 = R[i] % M[i] m1 = M[i] if m0 < m1: r0, r1 = r1, r0 m0, m1 = m1, m0 if m0 % m1 == 0: if r0 % m1 != r1: return (0, 0) # x nai continue g, im = inv_gcd(m0, m1) u1 = m1 // g if (r1 - r0) % g != 0: return (0, 0) # x nai x = ((((r1 - r0) // g) % u1) * im) % u1 r0 += x * m0 m0 *= u1 if r0 < 0: r0 += m0 return (r0, m0) N = int(input()) R = [] M = [] for i in range(N): x, y = map(int, input().split()) R.append(x) M.append(y) ans = crt(R, M) if ans[1] == 0: print(-1) else: if ans[0] == 0: print(ans[1] % (10 ** 9 + 7)) else: print(ans[0] % (10 ** 9 + 7))