#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000000;
const ll LINF=4000000000000000010;
int main(){
    int n;cin>>n;
    vector<P> v;
    ll a[500010],b[500010];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        v.push_back(P(a[i],b[i]));
    } 
    sort(all(v));
    ll sum=0,ma=0,ans=0;
    for(int i=0;i<n;i++){
        ma=max(ma,v[i].first-sum);
        ans=max(ans,sum+v[i].second+ma-v[i].first);
        sum+=v[i].second;
    }
    cout<<ans<<endl;
}	

