#include <bits/stdc++.h>
using namespace std;
vector<int> w[100010];
int n, max_ge, ans = INT_MAX, a[100010], NTF_AK_IOI;
int check(int x) {
  int tmp = 0, cnt = w[1].size();
  NTF_AK_IOI = 0;
  for (int i = 2; i <= max_ge; i++) {
    if (!w[i].size()) continue;
    for (int j = 0, ed = w[i].size() - x + 1; j < ed; j++)
      tmp += w[i][j], cnt++;
    for (int j = max((int)w[i].size() - x + 1, 0), ed = w[i].size(); j < ed;
         j++)
      a[++NTF_AK_IOI] = w[i][j];
  }
  sort(a + 1, a + NTF_AK_IOI + 1);
  for (int i = cnt + 1; i <= x; i++) tmp += a[i - cnt];
  return tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, op, val; i <= n; i++)
    scanf("%d %d", &op, &val), op++, max_ge = max(op, max_ge),
                                     w[op].push_back(val);
  for (int i = 2; i <= max_ge; i++) sort(w[i].begin(), w[i].end());
  int l = 0, r = n;
  while (l + 2 < r) {
    int lmid = (r + 2 * l) / 3, rmid = (2 * r + l) / 3;
    if (check(lmid) < check(rmid))
      r = rmid;
    else
      l = lmid;
  }
  for (int i = l; i <= r; i++) ans = min(ans, check(i));
  printf("%d\n", ans);
}
