#include <bits/stdc++.h>
#define ll long long
using namespace std;
unordered_map<int, set<int, greater<int>>> m;
int n, x, y;
ll ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
m[x].insert(y);
}
for (auto &i : m) {
ans += *i.second.begin();
}
cout << ans;
return 0;
}