#include <iostream>
#include <map>
#include <set>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <complex>
#include <list>

using namespace std;

int t[400500];

int sum (int v, int tl, int tr, int l, int r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	return max( sum (v*2, tl, tm, l, min(r,tm))
		, sum (v*2+1, tm+1, tr, max(l,tm+1), r) );
}

void update (int v, int tl, int tr, int pos, int new_val) {
	if (tl == tr)
		t[v] = new_val;
	else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			update (v*2, tl, tm, pos, new_val);
		else
			update (v*2+1, tm+1, tr, pos, new_val);
		t[v] = max(t[v*2] , t[v*2+1]);
	}
}
int g[100500];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<pair<int,int> > v(n);

    for (auto &x:v)
        cin >> x.first >> x.second;

    sort(v.begin(),v.end());

    update(1,0,n-1,n-1,n-1);
    g[n-1] = n-1;

    for (int i=n-2;i>=0;i--)
    {
        int x = v[i].first, a = v[i].second;

        auto it = lower_bound(v.begin(),v.end(), make_pair(x+a+1, -1)) - v.begin() - 1;

        if (it == i) {
            update(1,0,n-1, i, i);
            g[i] = i;
        } else {
            int mx = sum(1,0,n-1,i+1,it);
            update(1,0,n-1,i, mx);
            g[i] = mx;
        }

    }

    for (int i=1;i<n;i++)
    {
        g[i] = max(g[i], g[i-1]);
    }

    map<int,int> grmx;
    map<int,int> grmn;

    for (int i=0;i<n;i++)
    {
        if (!grmn.count(g[i]))
            grmn[g[i]] = v[i].first;
        grmx[g[i]] = max(grmx[g[i]], v[i].first + v[i].second);
    }

    vector<pair<int,int> > w1(grmx.begin(),grmx.end());
    vector<pair<int,int> > w2(grmn.begin(),grmn.end());

    long long int ans = 0;
    for (auto &x:v)
        ans += x.second;


    for (int i=0;i+1<w1.size();i++)
    {
        ans += w2[i+1].second - w1[i].second;
    }
    cout << ans;

    return 0;
}
/*

10100101
((()()))
()(())()

*/

/*
1010
(())
())(
*/
