n = int(input()) ws = [list(map(int, input().split())) for _ in range(n)] ws.sort(key = lambda x:x[0] + x[1]) inf = 1 << 60 dp = [0] for w, s in ws: dp += [inf] l = len(dp) for i in range(l - 1, 0, -1): if dp[i - 1] <= s: dp[i] = min(dp[i], dp[i - 1] + w) dp += [inf] for i in range(1, len(dp)): if dp[i] == inf: print(i - 1) exit()