#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 meh=INF;
vector<int128>pref(n+10,0);
fori(i,1,n){
pref[i]=pref[i-1]+v[i].ss;
if((pref[i-1]-v[i].ff)<meh){
meh=pref[i-1]-v[i].ff;
}
debug{
ll yesa,yesb;
yesa=pref[i];
yesb=meh;
cout<<yesa<<" "<<yesb<<endl;
}
if(ans<(pref[i]-v[i].ff-meh)){
ans=pref[i]-v[i].ff-meh;
}
}
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();
}
}