#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
const int maxn = 5e5 + 5;
const ll inf = 9e18;
int n;
pll arr[maxn];
int l, r;
ll sum, res = -inf;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n;
for(int i=0;i<n;++i){
cin >> arr[i].F >> arr[i].S;
}
sort(arr, arr+n);
for(int i=0;i<n;++i){
while(r - l > 1 && arr[l].F + arr[l].S < arr[l+1].F){
sum -= arr[l].S;
++l;
res = max(res, sum - (arr[r].F - arr[l].F));
}
sum += arr[i].S;
r = i;
res = max(res, sum - (arr[r].F - arr[l].F));
}
cout << res;
}