#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void Gcd(LL a,LL b,LL &x,LL &y)
{
if(!b)
{
x = 1, y = 0;
return;
}
Gcd(b, a % b, y, x);
y -= (a / b) * x;
}
LL CRT(LL k,LL* a,LL* b)
{
LL p = 1, ans = 0;
for (int i = 1;i <= k;i ++)
{
p = p * a[i];
}
for (int i = 1;i <= k;i++)
{
LL m = p / a[i], x, y;
Gcd(m, a[i], x, y);
ans = (ans + b[i] * m * x % p) % p;
}
return (ans % p + p) % p;
}
int n;
LL a[100010];
LL b[100010];
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i ++)
{
scanf("%lld%lld",a + i,b + i);
}
printf("%lld",CRT(n,a,b));
return 0;
}