#include<iostream>
#include<stdio.h>
#define int __int128
using namespace std;
struct node{
int a,b;
}a[100010];
bool cmp(node ccf,node ioi){
return ccf.a>ioi.a;
}
int mul(int a,int b,int mod){
int res=0;
while(b){
if(b&1)res=(res+a)%mod;
a=(a+a)%mod;b>>=1;
}
return res;
}
int gcd(int a,int b){
if(b)return gcd(b,a%b);
return a;
}
inline int read(){
int 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;
}
inline void write(long long x){
if(x<0){
putchar('-');
write(-x);return;
}
if(x>=10)write(x/10);
putchar(x%10+'0');return;
}
int x,y;
void exgcd(int A,int B){
if(B==0){
x=1;y=0;return;
}
exgcd(B,A%B);
int p=x;
x=y;
y=p-(A/B)*y;
return;
}
int n,ans;
signed main(){
n=read();
for(int i=1;i<=n;++i)a[i].a=read(),a[i].b=read();
for(int i=2;i<=n;++i){
int g=gcd(a[i].a,a[1].a);
int p=(a[i].b-a[1].b)/g;
exgcd(a[1].a,a[i].a);x=x*p;
int mod=a[1].a/g*a[i].a;
a[1].b=(mul(x,a[1].a,mod)+a[1].b)%mod;
a[1].a=mod;
}
a[1].b=(a[1].b%a[1].a+a[1].a)%a[1].a;
write(a[1].b);
return 0;
}