#include <bits/stdc++.h>
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
const long long mod = 1e4 + 7;
using namespace std;
int res, ans, N, l, r;
struct node {
  int x, y;
} P[100010];
int t[100010], sum[100010];
int use[100010];
int cmp(node a, node b) { return a.y < b.y; }
int fun(int n) {
  for (int i = 0; i <= 100000; i++) t[i] = sum[i];
  memset(use, 0, sizeof(use));
  res = 0;
  for (int i = 1; i <= N; i++)
    if (t[P[i].x] > n) {
      t[P[i].x]--;
      t[0]++;
      res += P[i].y;
      use[i] = 1;
    }
  for (int i = 1; i <= N; i++)
    if (t[0] <= n && !use[i]) {
      t[P[i].x]--;
      t[0]++;
      res += P[i].y;
      use[i] = 1;
    }
  return res;
}
int main() {
  while (scanf("%d", &N) != EOF) {
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= N; i++) {
      scanf("%d%d", &P[i].x, &P[i].y);
      sum[P[i].x]++;
    }
    sort(P + 1, P + N + 1, cmp);
    l = 0;
    r = 100000;
    while (l < r - 1) {
      int mid = (l + r) / 2;
      int mmid = (mid + r) / 2;
      if (fun(mid) <= fun(mmid)) {
        r = mmid;
      } else {
        l = mid;
      }
    }
    ans = 0x3f3f3f3f;
    for (int i = l; i <= r; i++) ans = min(ans, fun(i));
    printf("%d\n", ans);
  }
}
