n = int(input()) ws = [list(map(int,input().split())) for i in range(n)] ws.sort(key=sum) INF = 1<<60 dp = [INF]*(n+1) 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+[INF]).index(INF)-1)