#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 11;
int n;
int M = 1;
int ans = 0;
int phi[N];
int mul(int a, int b)
{
int res = 0;
for ( ; b ; b >>= 1)
{
if (b & 1) res = (res + a) % M;
a = (a + a) % M;
}
return res % M;
}
int pw(int a, int b)
{
int res = 1;
for ( ; b ; b >>= 1)
{
if (b & 1) res = mul(res, a) % M;
a = mul(res, a) % M;
}
return res % M;
}
signed main()
{
scanf("%lld", &n);
int a[N], m[N];
for (int i = 1 ; i <= n ; i ++ )
{
scanf("%lld%lld", &m[i], &a[i]);
M *= m[i];
}
for (int i = 1 ; i <= n ; i ++ ) // 处理出mi的欧拉函数
{
int tmp = phi[i] = m[i];
for (int j = 2 ; j <= tmp / j ; j ++ )
{
if (tmp % j == 0)
{
while (tmp % j == 0) tmp /= j;
phi[i] = phi[i] / j * (j - 1);
}
}
if (tmp != 1) phi[i] = phi[i] / tmp * (tmp - 1);
}
for (int i = 1 ; i <= n ; i ++ )
{
ans += mul(mul(a[i], (M / m[i])) % M, pw(M / m[i], phi[i] - 2)); //中国剩余定理公式
ans %= M;
}
printf("%lld", ans);
return 0;
}