import sys readline=sys.stdin.readline N=int(readline()) V,T=[],[] for i in range(N): v,t=map(int,readline().split()) V.append(v) T.append(t) M=max(T)+max(V) dp=[False]*(M+1) dp[0]=True for i in sorted([i for i in range(N)],key=lambda i:V[i]+T[i]): for j in range(min(M,T[i]+V[i]-1),V[i]-1,-1): dp[j]|=dp[j-V[i]] ans=0 for i in range(M+1): if dp[i]: ans=max(ans,i) print(ans)