#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const int MOD = 998244353;
void solve() {
int n; cin >> n;
vector<pii> a(n);
for (int i=0; i<n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
vector<ll> pref(n, 0);
pref[0] = a[0].second;
for (int i=1; i<n; i++) {
pref[i] = pref[i-1] + a[i].second;
}
ll ans=0;
for (int i=0; i<n; i++) {
for (int j=i; j<n; j++) {
ll restar = (i==0 ? 0 : pref[i-1]);
ll s = pref[j]-restar;
ans = max(ans, s-(a[j].first-a[i].first));
}
}
cout << ans << "\n";
}
//1 2 3 4 0
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
while (t--) {
solve();
}
return 0;
}