#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')if(ch=='-')f=-1,ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
int n,t,num;
int vis[10000005]={0};
unsigned long long ans;
int main(){
n=read();
for(int i=1;i<=n;++i){
num=read();
t=read();
if(t<=1)continue;
else if(vis[num])continue;
else{
ans+=t;
vis[num]=true;
}
}
printf("%lld",ans);
}