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

int main (){
	int n;
	cin >> n;
	
	vector<pair<int, int>> tugas(n);
	for (int i = 0; i < n; i++){
		int d, f;
		cin >> d >> f;
		tugas[i] = {d, f};
	}
	
	sort (tugas.begin(), tugas.end());
	int waktu = 0;
	int hadiah = 0;
	
	for (int i = 0; i < n; i++){
		waktu = waktu + tugas[i].first;
		hadiah += tugas[i].second - waktu;
	}
	cout << hadiah << '\n';
}