import sys # cf # http://techtipshoge.blogspot.com/2015/02/blog-post_15.html def gcd(a, b): if b == 0: return a return gcd(b, a%b) # return [g, x, y] # g = gcd(a, b) # x, y satisfies a x + b y = g def extgcd(a, b): if b == 0: return [a, 1, 0] g, x, y = extgcd(b, a%b) return [g, y, x - a/b * y] # eq0: x = a0 (mod m0) # eq1: x = a1 (mod m1) # returns [xt, mod] such that x = xt + k mod for integer k. def crt(eq0, eq1): a0, m0 = eq0 a1, m1 = eq1 g = gcd(m0, m1) if a0 % g != a1 % g: #raise Exception("x doesn't exist.") print(-1) sys.exit() if g > 1: m0 /= g m1 /= g while True: gt = gcd(m0, g) if gt == 1: break m0 *= gt g /= gt m1 *= g a0 %= m0 a1 %= m1 g, p, q = extgcd(m0, m1) x = a0 * q * m1 + a1 * p * m0 mod = m0 * m1 x = x % mod return [x, mod] n = int(raw_input()) eqs = [] for _ in xrange(n): a, m = map(int, raw_input().split()) eqs.append((a, m)) # solve the system x, mod = reduce(crt, eqs, (0, 1)) if x==0: x += mod MOD = 1000000007 print(x % MOD)