#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;

P ab[500005];
int r[500005];

signed main() {
	int n; cin >> n;
	rep(i, n) {
		int a, b; cin >> a >> b; ab[i] = P(a, b);
	}
	sort(ab, ab + n);

	rep(i, n)r[i + 1] = ab[i].second;
	rep(i, n)r[i + 1] += r[i];
	int ans = 0;
	int m = r[0] - ab[0].first;
	for (int i = 0; i<n; i++) {
		int M = r[i + 1] - ab[i].first;
		m = min(r[i]-ab[i].first, m);
		ans = max(ans, M - m);

	}
	cout << ans << endl;
}
