from fractions import gcd def inv(a, m): b, x, y = m, 1, 0 while b != 0: t = a // b a, b = b, a - t * b x, y = y, x - t * y pass return x % m def CRT(congs): x, m = 0, 1 for y, n in congs: _y, _n = y, n g = gcd(m, n) if x % g != y % g: return -1, -1 m //= g; l = m * n _m = m while True: t = gcd(m * _m, l) if t == m: break m = t n //= gcd(m, n) x %= m; x += (y - x % n) * inv(m, n) % n * m; m *= n pass return x, m mod = 10 ** 9 + 7 n = input() congs = [map(int, raw_input().split()) for _ in xrange(n)] ans = CRT(congs)[0] if ans == 0: ans = CRT(congs)[1] print -1 if ans == -1 else ans % mod