N=int(input()) L=100000 INF=10**9 dp=[INF]*(L+10**3+10) dp[0]=0 for _ in range(N): a,b=map(int, input().split()) for w in range(L+1)[::-1]: if dp[w]