import java.util.Scanner;
public class BOJ_14501 {
static int[] time;
static int[] price;
static int answer = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
time = new int[n];
price = new int[n];
for (int i = 0; i < n; i++) {
time[i] = sc.nextInt();
price[i] = sc.nextInt();
}
solve(n, 0, 0, 0);
System.out.println(answer);
}
private static void solve(int n, int t, int p, int i) {
if (t == n) {
if (p > answer)
answer = p;
return;
}
if (t > n)
return;
solve(n, t + time[i], p + price[i], i + time[i]);
solve(n, t + 1, p, i + 1);
}
}