#include <bits/stdc++.h>
using namespace std;
struct Voter {
  int vote, money, index;
} a[100001];
struct Candidate {
  int vote, index;
} c[100001];
int n, money[100001], head[100001], mark[100001];
bool compare1(Voter x, Voter y) { return x.money < y.money; }
bool compare2(Voter x, Voter y) {
  if (x.vote == y.vote) return x.money < y.money;
  return x.vote < y.vote;
}
bool compare3(Candidate x, Candidate y) { return x.vote > y.vote; }
int AmountMoney() {
  int res, amount = 0;
  for (int i = (0), _b = (c[1].vote - c[0].vote); i <= _b; i++) {
    amount += money[i];
  }
  res = amount;
  int currentC = 1, currentM = c[1].vote - c[0].vote;
  for (int myvote = (c[1].vote), _b = (0); myvote >= _b; myvote--) {
    while (currentC < 100001 && c[currentC].vote == myvote) currentC++;
    for (int i = (1), _b = (currentC); i < _b; i++) {
      if (a[head[c[i].index]].index >= currentM) {
        while (currentM >= 0 && mark[currentM] == 1) currentM--;
        if (currentM >= 0) amount -= money[currentM--];
        amount += a[head[c[i].index]].money;
      }
      mark[a[head[c[i].index]++].index] = 1;
    }
    while (currentM >= 0 && mark[currentM] == 1) currentM--;
    if (currentM >= 0) amount -= money[currentM--];
    res = min(res, amount);
    if (currentM < 0) return res;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].vote >> a[i].money;
    c[a[i].vote].vote++;
    if (a[i].vote == 0) {
      i--;
      n--;
    }
  }
  sort(a, a + n, compare1);
  for (int i = (0), _b = (n); i < _b; i++) {
    money[i] = a[i].money;
    a[i].index = i;
  }
  sort(a, a + n, compare2);
  int current = 0;
  for (int i = (1), _b = (100001); i < _b; i++) {
    head[i] = current;
    while (current < n && a[current].vote == i) current++;
  }
  for (int i = (1), _b = (100001); i < _b; i++) c[i].index = i;
  sort(c + 1, c + 100001, compare3);
  cout << AmountMoney();
  return 0;
}
