N = int(input()) lsAB = [tuple(map(int,input().split())) for i in range(N)] inf = float('INF') dp = [inf]*(10**5+1) dp[0] = 0 for i in range(N): dp2 = [inf]*(10**5+1) A,B = lsAB[i] for j in range(10**5+1): if j+A <= 10**5: dp2[j+A] = dp[j] for j in range(10**5+1): dp2[j] = min(dp2[j],dp[j]+B) dp = dp2 ans = inf for i in range(10**5+1): ans = min(ans,max(i, dp[i])) print(ans)