n = int(input()) ws = sorted((list(map(int,input().split())) for i in range(n)), key=sum) INF = 1<<60 dp = [INF]*(n+2) dp[0] = 0 for w,s in ws: for i in range(n)[::-1]: if dp[i] <= s: dp[i+1] = min(dp[i+1],dp[i]+w) print(dp.index(INF)-1)