#include<cstdio>
#include<iostream>
#include<set>
using namespace std;
set<int> s;
long long maxload[400010];
int n,order,dis;
long long ans,mini,pre,unload;
int main(){
freopen("boarding.in","r",stdin);
freopen("boarding.out","w",stdout);
cin>>n;
for(int i=1;i<=n;++i){
scanf("%d%lld",&order,&unload);
dis=n-i+order;
if (!s.count(dis)) s.insert(dis);
if (unload>maxload[dis]) maxload[dis]=unload;
}
while(!s.empty()){
mini=*s.begin();
ans+=mini-pre;
pre+=mini;
ans+=maxload[mini];
s.erase(mini);
}
cout<<ans<<endl;
}