N = int(input())
T = []; P = []
for i in range(N):
tmp = list(map(int, input().split(' ')))
T.append(tmp[0]); P.append(tmp[1])
dp = [0 for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
if T[i] + i <= N:
dp[i] = max(dp[i + 1], P[i] + dp[T[i] + i])
else:
dp[i] = dp[i + 1]
print(dp[0])