import sys input = sys.stdin.readline from operator import itemgetter N=int(input()) W=[tuple(map(int,input().split())) for i in range(N)] W.sort(key=lambda x:x[0]+x[1]) DP=[1<<60]*(N+1) DP[0]=0 for w,s in W: for i in range(N,-1,-1): if DP[i]==1<<60: continue if DP[i]<=s: DP[i+1]=min(DP[i+1],DP[i]+w) ANS=0 for i in range(N+1): if DP[i]!=1<<60: ANS=i print(ANS)