def solve(n, A, B): sum_b = 0 aa = bb = 0 for i in range(n): if aa < bb: aa += A[i] else: bb += B[i] sum_b += B[i] ma = max(aa, bb) dp = [0] * ma for i in range(n): a = A[i] b = B[i] for j in range(ma - a - 1, -1, -1): if dp[j + a] < dp[j] + b: dp[j + a] = dp[j] + b ans = ma for i in range(ma): ans = min(ans, max(i, sum_b - dp[i])) return ans def main(): n = int(input()) A = [0] * n B = [0] * n for i in range(n): A[i], B[i] = map(int, input().split()) ans = solve(n, A, B) print(ans) if __name__ == '__main__': main()