#include<iostream>
#include<cstdio>
#include<climits>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
__int128 m[15],a[15],lcm;
__int128 exgcd(__int128 a,__int128 b,__int128 &x,__int128 &y){//扩欧
if(!b){x=1,y=0;return a;}
__int128 re=exgcd(b,a%b,x,y),tmp=x;
x=y,y=tmp-(a/b)*y;
return re;
}
__int128 work(){
int i,j;__int128 d,x,y,re=0;
lcm=1;
for(i=1;i<=n;i++)lcm=lcm*m[i];//因为互质所以直接这么写了
for(i=1;i<=n;i++){
__int128 kl=lcm/m[i];
d=exgcd(kl,m[i],x,y);
x=(x%m[i]+m[i])%m[i];
re=(re+a[i]*x*kl)%lcm;
}
return re;
}
void _print(__int128 x)
{
if(x > 9) _print(x/10);
putchar(x%10 + '0');
}
void print(__int128 x)//输出
{
if(x < 0)
{
x = -x;
putchar('-');
}
_print(x);
}
__int128 read()
{
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int main()
{
//freopen("a.in","r",stdin);
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++){ m[i]=read();a[i]=read();}
print(work());
printf("\n");
}
return 0;
}