#include <bits/stdc++.h>
using namespace std;
vector<int> a[100005], p, q;
priority_queue<int> k;
int main() {
  int n, x, b, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &b);
    if (x) a[x].push_back(b);
    ans += b;
  }
  for (int i = 1; i <= 100000; ++i)
    if (a[i].size()) {
      sort(a[i].begin(), a[i].end());
      p.push_back(i);
    }
  int cnt = n, sum = ans;
  for (int i = 1; i <= n; ++i) {
    q.clear();
    if (p.size() == 0) break;
    for (int j = 0; j < p.size(); ++j) {
      sum -= a[p[j]].back();
      --cnt;
      k.push(-a[p[j]].back());
      a[p[j]].pop_back();
      if (a[p[j]].size()) q.push_back(p[j]);
    }
    while (cnt <= i && k.size()) {
      sum += -k.top();
      ++cnt;
      k.pop();
    }
    if (cnt > i) ans = min(ans, sum);
    p.clear();
    for (int j = 0; j < q.size(); ++j) p.push_back(q[j]);
  }
  cout << ans << endl;
  return 0;
}
