#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define ll long long
#define int128 __int128_t
#define fori(i,j,k) for(ll i=j; i<=k;i++)
#define study ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define all(s) s.begin(),s.end()
#define ins insert
#define ss second
#define ff first
#ifndef DB
#define DB 0
#endif
#define debugl(l) if constexpr((l)<DB)
#define debug debugl(0)
const ll sz=1e6+10;
ll INF=1e18;
ll mod=1e9+7;
ll add=1e6;
void work(){
ll n;
cin>>n;
vector<pair<ll,ll>>v(n+1);
fori(i,1,n){
cin>>v[i].ff>>v[i].ss;
}
v[0]={0,-INF};
sort(all(v));
int128 ans=(-(int128)1<<120);
ll l=1,r=1;
int128 val=0;
while(l<=r and r<=n){
val+=v[r].ss;
if(ans<(val-v[r].ff+v[l].ff))
ans=val-v[r].ff+v[l].ff;
while(v[l].ss<(v[l+1].ff-v[l].ff) and l<r){
l++;
if(ans<(val-v[r].ff+v[l].ff))
ans=val-v[r].ff+v[l].ff;
}
r++;
}
string s="";
bool ok=0;
if(ans<0){
ok=1;
}
if(ans==0){
s="0";
}
while(ans!=0){
ll last=abs(ans%10);
s+=(last+'0');
ans/=10;
}
reverse(all(s));
if(ok)
s="-"+s;
cout<<s<<endl;
}
int main()
{
//#ifndef LOCAL
// freopen("log1.txt","r",stdin);
// freopen("log2.txt","w",stdout);
//#endif
study;
ll t=1;
//cin>>t;
fori(i,1,t){
work();
}
}