#include<bits/stdc++.h>


using namespace std;

#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<int,ii> iii2;
typedef pair<ii,ii> iiii;

const long long mod = 1000000007LL;
const long long large = 2000000000000000000LL;

typedef unsigned long long ull;


vector<ii> maxi;
int ql,qr;
ii qv;
void query(int o,int l,int r){
	if(ql<=l&&qr>=r){
		qv = max(qv,maxi[o]);
	}else{
		int m = (l+r)/2;
		if(ql<=m) query(o*2,l,m);
		if(qr>m) query(o*2+1,m+1,r);
	}
}

int up;
ii uv;
void update(int o,int l,int r){
	if(l==r){
		maxi[o] = uv;
	}else{
		int m =(l+r)/2;
		if(up<=m) update(o*2,l,m);
		if(up>m) update(o*2+1,m+1,r);
		maxi[o] = max(maxi[o*2],maxi[o*2+1]);
	}
}

int main(){

    ios::sync_with_stdio(false);

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);


    int n;
    cin>>n;
    vector<int> a(n,0),c(n,0);
    for(int i=0;i<n;i++) cin>>a[i]>>c[i];

    vector<ii> e;
    for(int i=0;i<n;i++) e.push_back(ii(a[i],i));
    sort(e.begin(),e.end());

//    cout<<"!"<<endl;

    maxi.assign(4*n+10,ii(0,0));
    for(int i=0;i<n;i++){
    	int t= e[i].second;
    	up = i;
    	uv = ii(c[t]+a[t],i);
    	update(1,0,n-1);
    }

//    cout<<"!"<<endl;

    long long ans = 0;
    vector<int> vis(n,0);
    int st = 0;
    while(st!=n-1){
//    	cout<<st<<endl;
    	vis[st] = 1;
    	int t = e[st].second;
    	int rb = upper_bound(e.begin(),e.end(),ii(c[t]+a[t],n+10))-e.begin();
//    	cout<<rb<<"!!"<<endl;
    	qv = ii(-1,-1);
    	if(rb>=st+1){
    		ql = st+1;
    		qr = rb-1;
    		query(1,0,n-1);
    	}
//    	cout<<qv.second<<"!"<<endl;
    	if(qv.second==-1){
    		ans+=a[e[rb].second]-a[t];
    		st = rb;
    	}else{
    		int nt = qv.second;
    		int ntt = e[nt].second;
    		if(rb==n||a[ntt]+c[ntt]>a[t]+c[t]){
        		ans+=c[t];
        		st = nt;
    		}else{
        		ans+=a[e[rb].second]-a[t];
        		st = rb;
    		}
    	}
    }

    for(int i=n-1;i>=0;i--){
    	if(!vis[i]){
        	int t=e[i].second;
    		ans+=c[t];
    	}
    }
    cout<<ans<<endl;



    return 0;
}
