#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pll;
vector<pll> G[4000100]; //weight,vertex
priority_queue<pll,vector<pll>,greater<pll>> que;
ll d[4000100],INF = 100000000000000000;
void add_edge(int from,int to,ll weight){ G[from].push_back({weight,to}); }
void dijkstra(int s){
    que.push({0,s});
    while(que.size()){
        pll p = que.top(); que.pop();
        ll dis = p.first,pos = p.second;
        if(d[pos]!=INF) continue;
        d[pos] = dis;
        for(auto e:G[pos]){
            if(d[e.second]==INF) que.push({dis + e.first,e.second});
        }
    }
}

ll a[100010],c[100010],ans = 0;
vector<pair<ll,ll>> v;
int main(){
    int i,n; cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i] >> c[i];
        v.push_back({a[i],a[i] + c[i]});
        ans += c[i]; d[i] = INF;
    }
    sort(v.begin(),v.end());
    for(i=0;i<n;i++){
        if(i!=0) add_edge(i,i - 1,0);
        pair<ll,ll> p = {v[i].second,INF};
        int x = (upper_bound(v.begin(),v.end(),p) - v.begin());
        add_edge(i,x - 1,0);
        if(x<n) add_edge(i,x,v[x].first - v[i].second);
    }
    dijkstra(0);
    cout << d[n - 1] + ans << endl;
}