n = int(input()) M = 1<<30 INF = N = n*1000+1 dp = [INF]*N dp[0] = 0 for _ in range(n): a,b = map(int,input().split()) for i in range(N)[::-1]: dp[i] = min(dp[i]+b,dp[i-a] if i >= a else INF) ans = N for i in range(N): ans = min(ans,max(i,dp[i])) print(ans)