import numpy as np N = int(input()) MAX = 20000 homes = [tuple(map(int, input().split())) for _ in range(N)] homes.sort(key=lambda x: x[0] + x[1]) dp = np.zeros(MAX + 1, dtype=bool) dp[0] = True for v, t in homes: new_dp = dp.copy() new_dp[v:v + t] |= dp[:t] dp = new_dp print(np.nonzero(dp)[0].max())