N = int(input()) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) inf = 10 ** 18 M = 10 ** 5 + 5 pre = [inf] * M pre[0] = 0 for a, b in zip(A, B): dp = [inf] * M for i in range(M): dp[i] = pre[i] + b if i - a >= 0: dp[i] = min(dp[i], pre[i - a]) dp, pre = pre, dp ans = inf for i in range(M): ans = min(ans, max(i, pre[i])) print(ans)