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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// sort the cities by a_i
// then we can see that there exists a path in the optimal solution from the least beautiful city to the most beautiful city (a_1 to a_n)
// this is because in a hamiltonian cycle, we can see it as some circular path, and there is an arc on the circle in which we will accumulate all of our cost from (apart from the departure fee from each node), everything else is free (a_1 to a_n costs money, rest is free b)
// we want to minimize the path from a_1 to a_n
// which edges to add?
// edge backward is free
// edge forward to a node s.t a_j - (a_i + c_i) <= 0 and a_j - (a_i + c_i) > 0


// cost is max(c_i, a_j - a_i) <=> c_i + max(0, a_j - a_i - c_i)

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

	int n; cin >> n;
	vector<pii> cities(n);
	ll cost = 0;
	trav(p, cities) {
		cin >> p.first >> p.second;
		cost += p.second;
	}

	sort(all(cities));

	vector<ll> dist(n, 1LL << 60);
	priority_queue<pll> pq;
	pq.push(mp(0, 0));
	dist[0] = 0;
	while(!pq.empty()) {
		pll p = pq.top();
		pq.pop();

		int u = p.second;
		ll d = -p.first;

		// go back
		if(u - 1 >= 0 && dist[u - 1] > d) {
			dist[u - 1] = d;
			pq.push(mp(-d, u - 1));
		}

		// find first u in the future s.t a_j - a_i - c_i > 0
		ll curr = cities[u].first + cities[u].second;
		int low = u;
		for(int high = n; high >= 1; high /= 2) {
			while(low + high <= n - 1 && cities[low + high].first - curr <= 0) low += high;
		}

		// can go here for free
		if(low > u) {
			if(dist[low] > d) {
				dist[low] = d;
				pq.push(mp(-d, low));
			}
		}
		if(low + 1 <= n - 1) {
			if(dist[low + 1] > d + max(cities[low + 1].first - curr, 0ll)) {
				dist[low + 1] = d + max(cities[low + 1].first - curr, 0ll);
				pq.push(mp(-dist[low + 1], low + 1));
			}
		}
	}

	cout << dist[n - 1] + cost << endl;
    return 0;
}
