#include <bits/stdc++.h>
using std::max;
using std::min;
using std::sort;
using std::vector;
const int MAXN = 1e5 + 20;
int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') (c == '-') ? f = 1, c = getchar() : c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (48 ^ c), c = getchar();
  return (f) ? -x : x;
}
struct pad {
  int val, id;
  pad() {}
  pad(const int &V, const int &I) : val(V), id(I) {}
  bool operator<(const pad &B) const { return val > B.val; }
};
vector<pad> sup[MAXN], arr;
bool vis[MAXN];
long long check(const int &x, const int &m) {
  long long ret = 0;
  int nw = sup[1].size();
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= m; ++i)
    for (int j = sup[i].size() - 1; j + 1 >= x; --j) {
      ret += sup[i][j].val;
      vis[sup[i][j].id] = 1;
      ++nw;
    }
  for (int k = 0; k < (int)sup[1].size(); ++k) vis[sup[1][k].id] = 1;
  for (int k = arr.size() - 1; k >= 0 && nw < x; --k)
    if (!vis[arr[k].id]) {
      ret += arr[k].val;
      ++nw;
    }
  return ret;
}
int main() {
  int n = read(), m = 1;
  for (int i = 1; i <= n; ++i) {
    int p = read() + 1, c = read();
    sup[p].push_back(pad(c, i));
    arr.push_back(pad(c, i));
    m = max(m, p);
  }
  sort(arr.begin(), arr.end());
  for (int i = 2; i <= m; ++i) sort(sup[i].begin(), sup[i].end());
  long long ans = 0x3f3f3f3f3f3f3f3f;
  int l = max(1, (int)sup[1].size()), r = n;
  while (1) {
    int midl = (l + r) >> 1, midr = (midl + r) >> 1;
    if (midl == midr) {
      for (int i = l; i <= r; ++i) ans = min(ans, check(i, m));
      break;
    }
    long long tmpl = check(midl, m), tmpr = check(midr, m);
    if (tmpl < tmpr) {
      ans = min(ans, tmpr);
      r = midr - 1;
    } else {
      ans = min(ans, tmpl);
      l = midl + 1;
    }
  }
  printf("%lld", ans);
}
