from math import gcd from bisect import bisect_left, bisect_right from heapq import heappop, heappush from collections import defaultdict, deque, Counter import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline def extgcd(a, b): if b == 0: return 1, 0, a q, r = a//b, a % b x, y, d = extgcd(b, r) s, t = y, x-y*q return s, t, d def crt(b, m): r = 0 M = 1 for i in range(len(b)): s,t, d = extgcd(M, m[i]) if (b[i] - r) % d != 0: return [0, -1] lcm = M * m[i] // d r += M * ((b[i] - r) // d) * s M = lcm r %= M return r, M n = int(input()) b = [] m = [] for i in range(n): x,y = map(int,input().split()) b.append(x) m.append(y) r, M = crt(b,m) if M != -1 and r != 0: print(r) else: print(M)