#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<pair<long long,long long>> a(N+1);
for(int i=1;i<=N;i++)
cin >> a[i].first >> a[i].second;
sort(a.begin()+1,a.end());
vector<long long> pref(N+1);
for(int i=1;i<=N;i++)
pref[i]=pref[i-1]+a[i].second;
long long ans = LLONG_MIN;
long long best = LLONG_MIN;
for(int r=1;r<=N;r++){
best = max(best, a[r].first - pref[r-1]);
ans = max(ans, best + pref[r] - a[r].first);
}
cout << ans << "\n";
}