#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n;
long long t[200005],s[200005],f[200005];
long long l,r,mid;
void init(){
cin>>n;
for (int i=1;i<=n;i++)
scanf("%I64d%I64d",&s[i],&t[i]);
for (int i=1;i<=n;i++)
f[i]=i-n;
}
bool judge(long long tim){
int i,j;
i=n;
while (i>0){
if (s[i]-f[i]+t[i]>tim) return false;
if (s[i]<f[i]) {
tim-=s[i]-f[i]+t[i];
s[i-1]=f[i]-1;
}
else if (s[i]>=f[i]){
if (s[i]>=f[i]+t[i])
s[i-1]=s[i]-1-t[i];
else {
s[i-1]=f[i]-1;
tim-=f[i]+t[i]-s[i];
}
}
i--;
}
return true;
}
void solve(){
l=0;r=100000000000;
while (l<r){
if (l==r-1){
if (judge(l)) r=l;
else l=r;
break;
}
mid=(l+r)/2;
if (judge(mid)) r=mid;
else l=mid;
}
printf("%I64d",l);
}
int main(){
freopen("boarding.in","r",stdin);
freopen("boarding.out","w",stdout);
init();
solve();
return 0;
}