#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int MAX_E2 = 1 << 18;
const int MAX_A = 100000;
const int INF = 1 << 30;
int uas[MAX_N];
pair<int, int> ps[MAX_N], cns[MAX_A];
vector<int> cvs[MAX_A];
bool used[MAX_A];
int check(int m, int uan, int c0, int x) {
  memset(used, false, sizeof(used));
  int c = c0, sum = 0;
  for (int i = uan - 1; i >= 0 && cns[i].first > x; i--) {
    vector<int> &cv = cvs[cns[i].second];
    int maxj = cns[i].first - x;
    for (int j = 0; j < maxj; j++)
      sum += ps[cv[j]].first, c++, used[cv[j]] = true;
  }
  for (int i = 0; i < m && c <= x; i++)
    if (!used[i]) sum += ps[i].first, c++;
  return (c > x) ? sum : INF;
}
int main() {
  int n;
  scanf("%d", &n);
  int m = 0, c0 = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (!a)
      c0++;
    else {
      a--;
      uas[m] = a;
      ps[m++] = pair<int, int>(b, a);
    }
  }
  sort(uas, uas + m);
  int uan = unique(uas, uas + m) - uas;
  for (int i = 0; i < m; i++) {
    int ai = lower_bound(uas, uas + uan, ps[i].second) - uas;
    ps[i].second = ai;
  }
  sort(ps, ps + m);
  for (int i = 0; i < m; i++) cvs[ps[i].second].push_back(i);
  for (int i = 0; i < uan; i++) cns[i] = pair<int, int>(cvs[i].size(), i);
  sort(cns, cns + uan);
  int x0 = 0, x1 = cns[uan - 1].first;
  while (x0 + 2 < x1) {
    int xx0 = (x0 * 2 + x1) / 3;
    int xx1 = (x0 + x1 * 2) / 3;
    int sum0 = check(m, uan, c0, xx0);
    int sum1 = check(m, uan, c0, xx1);
    if (sum0 >= sum1)
      x0 = xx0;
    else
      x1 = xx1;
  }
  int minsum = INF;
  for (int x = x0; x <= x1; x++) {
    int sum = check(m, uan, c0, x);
    if (minsum > sum) minsum = sum;
  }
  printf("%d\n", minsum);
  return 0;
}
