#include<bits/stdc++.h>#define int long long#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;pair<int,int>extgcd(inta,intb){if(b==0){// a * x + 0 * y = gcd(a, 0) = areturn{1,0};}autop=extgcd(b,a%b);return{p.S,p.F-(a/b)*p.S};}intget_inv(inta,intm){pair<int,int>p=extgcd(a,m);intx=p.F;return(x%m+m)%m;}pair<int,int>CRT(intk1,intp1,intk2,intp2){intK=k1*k2;intP=((__int128)((p1*k2)%K)*get_inv(k2,k1))%K+((__int128)((p2*k1)%K)*get_inv(k1,k2))%K;P=(P%K+K)%K;return{K,P};}signedmain(){intn;cin>>n;pair<int,int>cur;for(inti=1;i<=n;i++){intk,p;cin>>k>>p;// x % k = pif(i==1){cur.F=k,cur.S=p;}else{cur=CRT(cur.F,cur.S,k,p);}}cout<<cur.S<<'\n';}
pair<int,int>CRT(intk1,intp1,intk2,intp2){intc=p2-p1;intd=__gcd(k2,k1);assert(c%d==0);// c % d != 0 無解intx=(c*extgcd(k1/d,k2/d).F)/d%(k2/d);intK=(k1*k2)/d;// lcm = (a * b) / gcd(a, b)intP=(p1+k1*x)%K;return{K,((P>0)?P:P+K)};}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;intp[100005],k[100005];intn;pair<int,int>extgcd(inta,intb){if(b==0){// a * x + 0 * y = gcd(a, 0) = areturn{1,0};}autop=extgcd(b,a%b);return{p.S,p.F-(a/b)*p.S};}pair<int,int>CRT(intk1,intp1,intk2,intp2){intc=p2-p1;intd=__gcd(k2,k1);intx=(__int128)((__int128)c*extgcd(k1/d,k2/d).F)/d%(k2/d);intK=(__int128)((__int128)k1*k2)/d;intP=(__int128)(p1+k1*x)%K;return{K,((P>0)?P:P+K)};}signedmain(){intn;cin>>n;pair<int,int>cur;for(inti=1;i<=n;i++){intk,p;cin>>k>>p;// x % k = pif(i==1){cur.F=k,cur.S=p;}else{cur=CRT(cur.F,cur.S,k,p);}}cout<<cur.S<<'\n';}