#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<pair<ll, ll>> ab;
    for(int i = 0;i < N;i++){
        ll A, B;
        cin >> A >> B;
        ab.emplace_back(A, B);
    }
    sort(ab.begin(), ab.end());
    vector<ll> sum(N + 1), v(N + 1);
    for(int i = 0;i < N;i++){
        sum[i + 1] = sum[i] + ab[i].second;
        v[i] = sum[i] - ab[i].first;
    }
    ll res = 0, mi = v[0];
    for(int i = 0;i < N;i++){
        mi = min(mi, v[i]);
        res = max(res, sum[i + 1] - ab[i].first - mi);
    }
    cout << res << endl;
    return 0;
}

