#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
#define lll array<ll, 3>
#define pll array<ll, 2>
#define endl '\n'
using namespace std;
const ll N = 1e6 + 5;
const ll inf = 1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void sl(){
ll n; cin >> n;
vector<pll>a(n); ll sm;
for(auto &[x, y] : a) cin >> x >> y;
sort(all(a)); ll res = 0;
for(ll i = 0; i < n; i++){
sm = 0;
for(ll j = i; j < n; j++){
sm += a[j][1];
res = max(res, sm - a[j][0] + a[i][0]);
}
}
cout << res << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll t = 1; //cin >> t;
while(t--) sl();
}