#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 500010
ll n;pair<ll,ll> a[N];
int main(){
    cin>>n;
    lol(i,n)cin>>a[i].first>>a[i].second;
    sort(a,a+n);
    ll sum=0,mini=-a[0].first,ans=0;
    lol(i,n){
	sum+=a[i].second;
	ans=max(ans,sum-a[i].first-mini);
	if(i<n-1){
	    mini=min(mini,sum-a[i+1].first);
	}
    }
    cout<<ans<<endl;
    return 0;
}

