def extgcd(a, b): if b == 0: return (1, 0) x, y = extgcd(b, a % b) return (y, x - a / b * y) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def solve(a1, m1, a2, m2): g = gcd(m1, m2) l = m1 / g * m2 p, q = extgcd(m1, m2) if (a2 - a1) % g != 0: return (0, -1) p *= (a2 - a1) / g x = p * m1 + a1 x %= l x += l x %= l return (x, l) N = input() X = [0] * N Y = [0] * N for i in xrange(N): X[i], Y[i] = map(int, raw_input().split()) for i in xrange(1, N): X[0], Y[0] = solve(X[0], Y[0], X[i], Y[i]) if Y[0] == -1: print -1 exit() MOD = 10 ** 9 + 9 print X[0] % MOD