#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+100;
struct re{
int a,b;
}m[N];
int n,kk,ll,l;
signed main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld%lld",&m[i].a,&m[i].b);
int len=m[1].a,now=m[1].b;
for(int i=2;i<=n;i++){
now=max(now,len-now);
kk=min(m[i].b,m[i].a-m[i].b);
ll=m[i].a-kk;
l=len-now;
if(ll>l)
len+=ll-l;
// cout<<ll<<endl;
// cout<<kk<<" "<<now<<" "<<ll<" "<<l<<endl;
}
printf("%lld",len);
}