#include <bits/stdc++.h>
// #define int long long
#define LL long long
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e6 + 10;
struct Node
{
int t, w;
bool operator< (const Node& W) const
{
return w > W.w;
}
}q[N];
int n, last; //last表示1-last的位置都被占用了
bool st[N];
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
cin >> q[i].t >> q[i].w;
}
sort(q + 1, q + n + 1);
int sum = 0;
for (int i = 1; i <= n; i ++ )
{
if (q[i].t <= last) continue; //没地方放,拿不了学分
//疑问:为什么这里j > last不行
for (int j = q[i].t; j >= 1; j -- )
{
if (!st[j])
{
st[j] = true;
sum += q[i].w;
break;
}
if(j == 1) last = q[i].t;
}
}
cout << sum << endl;
return 0;
}