#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1
const int N = 2e5 + 7;
const int TN = 4 * N;
const int oo = 1e18;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n, pre[N], best, ans;
pii a[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].ff >> a[i].ss;
}
sort (a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
pre[i] = pre[i - 1] + a[i].ss;
}
for (int i = 1; i <= n; i++) {
best = max (best, a[i].ff - pre[i - 1]);
ans = max (ans, best + pre[i] - a[i].ff);
} cout << ans;
return 0;
}