import java.io.*;
import java.util.*;

public class jumps_pk {

	int n;

	class Job implements Comparable<Job> {
		int id, d, w;

		public Job(int id, int w, int d) {
			this.id = id;
			this.d = n - d;
			this.w = w;
		}

		@Override
		public int compareTo(Job arg0) {
			if (w != arg0.w)
				return w - arg0.w;
			else
				return id - arg0.id;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + d;
			result = prime * result + id;
			result = prime * result + w;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Job other = (Job) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (d != other.d)
				return false;
			if (id != other.id)
				return false;
			if (w != other.w)
				return false;
			return true;
		}

		private jumps_pk getOuterType() {
			return jumps_pk.this;
		}

	}

	void solve() throws IOException {
		n = nextInt();
		ArrayList<Job>[] jobs = new ArrayList[n + 1];

		TreeSet<Job> status = new TreeSet<jumps_pk.Job>();

		for (int i = 0; i < n + 1; i++) {
			jobs[i] = new ArrayList<jumps_pk.Job>();
		}
		long ans = 0;

		for (int i = 0; i < n; i++) {
			Job addon = new Job(i, nextInt(), nextInt());
			if (addon.d > 0) {
				jobs[addon.d - 1].add(addon);
			} else {
				ans = ans + addon.w;
			}
		}

		for (int i = 0; i < n; i++) {
			for (Job j : jobs[i]) {
				status.add(j);
			}

			while (status.size() > i + 1) {
				ans = ans + status.first().w;
				status.remove(status.first());
			}
		}

		out.println(ans);
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			br = new BufferedReader(new FileReader(new File("jumps.in")));
			out = new PrintWriter("jumps.out");
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new jumps_pk().run();
	}

	String nextToken() throws IOException {
		while ((st == null) || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}
}
