#include<cstdio>
#include<algorithm>
using namespace std;
int d[200050];
int s[200050];
int t[200050];
bool f[200050];
int n;
int tot;
int sum=0;
int main(){
freopen("boarding.in","r",stdin);
freopen("boarding.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d%d",&s[i],&t[i]);
d[i]=i-n;
}
while (sum!=n){
tot++;
for (int i=n;i;i--){
if (f[i]){
continue;
}
if (d[i]==s[i]){
if (t[i]){
t[i]--;
if (!t[i]){
sum++;
f[i]=1;
d[i]=0x3f3f3f3f;
}
}
else{
continue;
}
}
else{
if (d[i+1]!=d[i]+1){
d[i]++;
}
}
}
}
printf("%d\n",tot+1);
return 0;
}