#include <bits/stdc++.h>
using namespace std;

typedef pair<long long, long long> ii;
const long long INF = 1LL << 61;

ii ac[100005];
long long a[100005];
long long c[100005];
long long dp[100005];

struct segtree{
    long long val[(1<<18)+5];

    void init(int i = 1, int s = 0, int e = 100002){
        if(s == e){
            val[i] = INF;
        }else{
            int l = (i<<1);
            int r = (i<<1)|1;
            int m = (s+e)>>1;
            init(l, s, m);
            init(r, m+1, e);
            val[i] = min(val[l], val[r]);
        }
    }

    long long rmq(int x, int y, int i = 1, int s = 0, int e = 100002){
        if(x <= s && e <= y){
            return val[i];
        }else{
            int l = (i<<1);
            int r = (i<<1)|1;
            int m = (s+e)>>1;
            if(x > m){
                return rmq(x, y, r, m+1, e);
            }else if(y <= m){
                return rmq(x, y, l, s, m);
            }else{
                return min(rmq(x, y, r, m+1, e), rmq(x, y, l, s, m));
            }
        }
    }

    void update(int p, long long v, int i = 1, int s = 0, int e = 100002){
        if(s == e){
            val[i] = v;
            return;
        }else{
            int l = (i<<1);
            int r = (i<<1)|1;
            int m = (s+e)>>1;
            if(p > m){
                update(p, v, r, m+1, e);
            }else if(p <= m){
                update(p, v, l, s, m);
            }
            val[i] = min(val[l], val[r]);
        }
    }
};


ii aplusc[100005];

long long solve(int start1, int end1){
    for(int i = start1; i <= end1; i ++){
        tie(a[i-start1], c[i-start1]) = ac[i];
    }
    int m = end1-start1+1;

    /*
    dp[i] = min(dp[j] + max((a[i]-a[j]) - c[j], 0))
    dp[i] = min(dp[j] + max( a[i] - a[j] - c[j], 0))
    dp[i] = min(dp[j] + max( a[i] - (a[j] + c[j]), 0))
    */
    // sort a[j]+c[j] by value
    for(int i = 0; i < m; i ++){
        aplusc[i] = ii(a[i]+c[i], i);
    }
    sort(aplusc, aplusc+m);

    segtree* segtree1 = new segtree();
    segtree* segtree2 = new segtree();
    segtree1->init();
    segtree2->init();

    dp[0] = 0;
    int findIndx = lower_bound(aplusc, aplusc+m, ii(a[0]+c[0], 0)) - aplusc;
    segtree1->update(findIndx, dp[0]);
    segtree2->update(findIndx, dp[0] - (a[0]+c[0]));
    for(int i = 1; i < m; i ++){
        dp[i] = INF;

        long long tempVal = a[i];
        int cutoff = lower_bound(aplusc, aplusc+m, ii(tempVal, -1)) - aplusc;

        // beyond cutoff index, a[j]+c[j] dominates, hence find min value of dp[j].
        // before cutoff index, a[i] dominates, hence find min value of dp[j] - (a[j]+c[j]);

        long long case1 = segtree1->rmq(cutoff, m-1);
        long long case2 = INF;
        if(cutoff > 0){
            case2 = segtree2->rmq(0, cutoff-1) + a[i];
        }

        dp[i] = min(case1, case2);

        /*for(int j = 0; j < i; j ++){
            long long cost = max( a[i] - (a[j] + c[j]), 0LL );
            dp[i] = min(dp[i], dp[j] + cost);
            printf("cost(%d, %d)=%d\n", i, j, cost);
        }*/
        //printf("dp[%d]=%lld\n", i, dp[i]);

        int findIndx = lower_bound(aplusc, aplusc+m, ii(a[i]+c[i], i)) - aplusc;
        segtree1->update(findIndx, dp[i]);
        segtree2->update(findIndx, dp[i] - (a[i]+c[i]));
    }

    return dp[m-1];
}

int main(){
    int n;
    scanf("%d", &n);

    long long ans = 0;
    for(int i = 0; i < n; i ++){
        int a, c;
        scanf("%d%d", &a, &c);
        ac[i] = ii(a, c);
        ans += c;
    }
    ii start2 = ac[0];

    sort(ac, ac+n);
    int startIndx = lower_bound(ac, ac+n, start2) - ac;

    for(int i = 0; i < n; i ++){
        //printf("ii(%d, %d)\n", ac[i].first, ac[i].second);
    }

    long long temp1 = solve(0, n-1);
    long long temp2 = 0;
    //long long temp2 = solve(startIndx, );
    printf("%lld", ans + temp1 + temp2);
    return 0;
}
