# -*- coding: UTF-8 -*- def exgcd(a: int, b: int) -> (int, int, int): # 返回 (gcd(a,b), x, y) 满足 gcd(a,b)=ax+by x1, x2, x3, x4 = 1, 0, 0, 1 while b != 0: q = a // b x1, x2, x3, x4, a, b = x3, x4, x1 - x3 * q, x2 - x4 * q, b, a - b * q return a, x1, x2 def gcrt2(a: int, m1: int, b: int, m2: int) -> (int, int): d, x, y = exgcd(m1, m2) bma = b - a if bma % d != 0: return -1, -1 t, y = m2 // d, bma // d res = x * y % t if res < 0: res += t return res * m1 + a, m1 * t if __name__ == '__main__': n = int(input()) ans, m0 = 0, 1 for _ in range(0, n): d, c = (int(i) for i in input().split(' ')) ans, m0 = gcrt2(ans, m0, c, d) if ans == -1: break if ans == -1: print(-1) elif ans == 0: print(m0 % 1000000007) else: print(ans % 1000000007)