#include <bits/stdc++.h>
using namespace std;
const int MAXA = 1e5 + 5;
int N, nvote;
vector<int> bribe[MAXA];
int moo(int x) {
  int ans = 0, v = nvote;
  priority_queue<int, vector<int>, greater<int> > pq;
  for (int i = 1; i < MAXA; i++) {
    vector<int> &ref = bribe[i];
    for (int j = 0, siz = ref.size(); j < siz; j++) {
      if (j < x) {
        pq.push(ref[j]);
      } else {
        ans += ref[j];
        v++;
      }
    }
  }
  for (; v <= x; v++) {
    ans += pq.top();
    pq.pop();
  }
  return ans;
}
int main() {
  if (fopen("codeforces458CNo2.in", "r")) {
    freopen("codeforces458CNo2.in", "r", stdin);
  }
  scanf("%d", &N);
  for (int i = 0, a, b; i < N; i++) {
    scanf("%d %d", &a, &b);
    if (a) {
      bribe[a].push_back(b);
    } else {
      nvote++;
    }
  }
  for (int i = 1; i < MAXA; i++) {
    sort(bribe[i].begin(), bribe[i].end(), greater<int>());
  }
  int lo = 0, hi = N - 1;
  while (hi - lo >= 3) {
    int third = (hi - lo) / 3;
    int lft = lo + third, rt = hi - third;
    if (moo(lft) < moo(rt)) {
      hi = rt;
    } else {
      lo = lft;
    }
  }
  int ans = 2.14e9;
  for (int i = lo; i <= hi; i++) {
    int m = moo(i);
    if (ans > m) {
      ans = m;
    }
  }
  printf("%d\n", ans);
}
