'''
中国剩余定理应用
'''
# 求a, b最大公约数,同时求出裴蜀定理中的一组系数x, y, 满足x*a + y*b = gcd(a, b)
def exp_gcd(a, b):
flag = True
if a > b:
flag = False
a, b = b, a
if a == 0:
return (b, 0, 1) if flag else (b, 1, 0)
gcd_val, x, y = exp_gcd(b%a, a)
new_x = y - x * (b // a)
new_y = x
return (gcd_val, new_x, new_y) if flag else (gcd_val, new_y, new_x)
# 求val对mod取模的逆元, 也就是(val * ans) 和 1 对 mod 求模同余
def get_mul_mod_rev_meta(val, mod):
gcd_val, x, _ = exp_gcd(val, mod)
return None if gcd_val != 1 else x
n = int(input())
a_arr = []
m_arr = []
M = 1
for i in range(n):
m, a = map(int, input().split())
m_arr.append(m)
a_arr.append(a)
M *= m
ans = 0
for i in range(n):
ans += (a_arr[i] * (M // m_arr[i]) * get_mul_mod_rev_meta(M // m_arr[i], m_arr[i])) % M
ans %= M
print(ans)