#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T> void chmin(T &a,T b){if(a>b) a=b;}
template<typename T> void chmax(T &a,T b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++){
    Int a,b;
    cin>>a>>b;
    v.emplace_back(a,b);
  }
  sort(v.begin(),v.end());

  vector<Int> a,b;
  for(Int i=0;i<n;i++){
    if(a.empty()||a.back()!=v[i].first){
      a.emplace_back(v[i].first);
      b.emplace_back(v[i].second);
    }else{
      b.back()+=v[i].second;
    }  
  }

  //for(Int i=0;i<n;i++) cout<<i<<":"<<a[i]<<" "<<b[i]<<endl;

  vector<Int> c(b.size());
  partial_sum(b.begin(),b.end(),c.begin());

  // [l,r]
  auto get=[&](Int l,Int r){
    if(l) return c[r]-c[l-1];
    return c[r];
  };

  if(0){
    Int ans=0;
    for(Int i=0;i<(Int)a.size();i++)
      for(Int j=i;j<(Int)a.size();j++)
	chmax(ans,get(i,j)-(a[j]-a[i]));
    
    cout<<ans<<endl;
  }
  
  Int ans=0,l=0,r=0;
  for(Int i=0;i<(Int)a.size();i++){
    while(l<i&&a[l+1]-a[l]>=b[l]) l++;
    chmax(ans,get(l,i)-(a[i]-a[l]));
    
    chmax(r,l);
    while(r+1<i){
      while(r+1<i&&a[r+1]-a[l]<=get(l,r)) r++;
      if(a[r+1]-a[l]>=get(l,r)) l=r+1;
      else break;
    }
    chmax(ans,get(l,i)-(a[i]-a[l]));
  }
  
  cout<<ans<<endl;
  
  return 0;
}

