#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 1005
int n;
int vis[M];
int s[M],d[M];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&s[i],&d[i]);
//vis[i]=0;
}
ll it=0;
for(int j=1;j<=n;j++)
{
while(it<s[j]) {it++;}
while(1)
{
if((it-s[j])%d[j]==0)
{
if(j!=n)
it++;
//cout<<"it"<<it<<endl;
break;
}
else
it++;
}
}
printf("%I64d\n",it);
return 0;
}
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 505
int n;
ll k;
int a[M];
int main()
{
scanf("%d%I64d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
ll num=0;
int it=1;
int next,ans;
while(num<k)
{
if(it==n)
next=1;
else
next=it+1;
if(a[it]>a[next])
{
num++;
if(num==k)
{
ans=a[it];
break;
}
if(a[it]==n)
{
ans=a[it];
break;
}
int temp=a[it];
a[it]=a[next];
a[next]=temp;
}
it=next;
}
printf("%d\n",ans);
return 0;
}