#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int N = 5e5+5 ;
int n ;
vector<pair<ll,ll>> vp ;
ll arr[N] , brr[N] , pre[N] , mini=1e15 , maxi ;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) ;
cin >> n ;
vp.resize(n) ;
for(int i=0 ; i<n ; i++) cin >> vp[i].first >> vp[i].second ;
sort(vp.begin(),vp.end()) ;
for(int i=1 ; i<=n ; i++){
arr[i]=vp[i-1].first , brr[i]=vp[i-1].second ;
pre[i]=pre[i-1]+brr[i] ;
mini=min(mini,pre[i-1]-arr[i]) ;
maxi=max(maxi,pre[i]-arr[i]-mini) ;
}
cout << maxi << '\n' ;
return 0 ;
}