def CRT(BMlist): # Extended Euclidean Algorithm def extgcd(a, b): if b: d, y, x = extgcd(b, a % b) y -= (a // b)*x return d, x, y return a, 1, 0 r = 0; M = 1 for b,m in BMlist: d,p,q = extgcd(M,m) if (b-r)%d != 0: return 0,-1 r += M*((b-r)//d*p%(m//d)) M *= m//d return r%sml,M%sml import math BMlist = [] ans = 1 sml = 10**9+7 N = int(input()) for i in range(N): x,y = map(int, input().split()) BMlist.append((x,y)) g = math.gcd(ans,y) ans = ((ans*y)//g)%sml r,m = CRT(BMlist) if r != 0: print(r) elif m == -1: print(-1) else: print(ans)