package BOJ.BruteForce;
import java.util.Scanner;
/**
* 풀이참고
* https://mygumi.tistory.com/151
*/
public class BOJ_14501 {
static int[] t;
static int[] p;
static int[] dp;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
t = new int[n + 1];
p = new int[n + 1];
dp = new int[n + 1];
for (int i = 1; i <= n; i++) {
t[i] = sc.nextInt();
p[i] = sc.nextInt();
dp[i] = p[i];
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (i - j >= t[j])
dp[i] = Math.max(p[i] + dp[j], dp[i]);
}
}
int max = 0;
for (int i = 1; i <= n; i++) {
if (i + t[i] <= n + 1) {
if (max < dp[i]) {
max = dp[i];
}
}
}
System.out.println(max);
}
}