/**
*中国剩余定理
*/
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cstring>
#include<cmath>
#define LL __int64
using namespace std;
/**
*gcd(a,b)=d;则存在x,y,使d=ax+by
*extended_euclid(a,b)=ax+by
*/
LL extended_euclid(LL a,LL b,LL &x,LL &y){//扩张欧几里的算法
int d;
if(b==){
x=; y=;
return a;
}
d=extended_euclid(b,a%b,y,x);
y=y-a/b*x;
return d;
}
/**
*x=b[i](modw[i]) o<i<len
*w[i]>0,且w[]中任意两个数互质
*/
LL chinese_remainder(int b[],int w[],int len){
LL res,i,d,x,y,n,m;
res=; n=;
for(i=;i<len;i++) n*=w[i];
for(i=;i<len;i++){
m=n/w[i];
extended_euclid(w[i],m,x,y);
res=(res+y*m*b[i])%n;
}
return (n+res%n)%n;
} int main()
{
int len,b[],w[];
while(cin>>len){
for(int i=;i<len;i++){
cin>>w[i]>>b[i];
}
cout<<chinese_remainder(b,w,len)<<endl; }
return ;
}