#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
template <class T>
void print(vector<T> v, int sz = -1) {
  if (sz == -1) sz = int((v).size());
  cerr << "[";
  if (sz) cerr << v[0];
  for (int i = (1); i < (sz); ++i) cerr << ", " << v[i];
  cerr << "]" << endl;
}
const double PI = acos(-1.0);
const int MAXN = (int)1e5 + 10;
int n;
int a[MAXN], b[MAXN];
vector<int> votes[MAXN];
long long INF = (long long)1e18;
void read() {
  cin >> n;
  for (int i = (0); i < ((n)); ++i) {
    cin >> a[i] >> b[i];
    votes[a[i]].push_back(b[i]);
  }
  for (int i = (0); i < ((MAXN)); ++i)
    sort((votes[i]).begin(), (votes[i]).end());
}
long long needed(int cur_votes) {
  long long ans = 0;
  int firstVotes = int((votes[0]).size());
  int firstShouldHave = 0;
  for (int i = (1); i < (MAXN); ++i) {
    if (int((votes[i]).size()) > cur_votes) {
      int toTake = int((votes[i]).size()) - cur_votes;
      firstShouldHave = max(firstShouldHave, cur_votes + 1);
      for (int j = (0); j < ((toTake)); ++j) {
        ans += votes[i][j];
      }
      firstVotes += toTake;
    } else {
      firstShouldHave = max(firstShouldHave, int((votes[i]).size()) + 1);
    }
  }
  firstShouldHave = cur_votes + 1;
  if (firstVotes < firstShouldHave) {
    vector<int> b;
    for (int i = (1); i < (MAXN); ++i) {
      int toTake = int((votes[i]).size()) - cur_votes;
      if (toTake < 0) {
        toTake = 0;
      }
      for (int j = (toTake); j < (int((votes[i]).size())); ++j) {
        b.push_back(votes[i][j]);
      }
    }
    sort((b).begin(), (b).end());
    int toTake = firstShouldHave - firstVotes;
    if (toTake > int((b).size())) {
      return INF;
    }
    for (int i = (0); i < ((toTake)); ++i) {
      ans += b[i];
    }
  }
  return ans;
}
void solve() {
  int lo = 0, hi = n - 1;
  long long ans = INF;
  for (int it = (0); it < ((100)); ++it) {
    int mid1 = lo + (hi - lo) / 3;
    int mid2 = hi - (hi - lo) / 3;
    long long fir = needed(mid1);
    long long sec = needed(mid2);
    ans = min(ans, fir);
    ans = min(ans, sec);
    if (fir > sec) {
      lo = mid1;
    } else {
      hi = mid2;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    read();
    solve();
  }
  return 0;
}
