n = int(input()) ws = sorted((tuple(map(int, input().split())) for _ in range(n)), key=lambda p: sum(p)) dp = [0] for w, s in ws: sz = len(dp) if dp[-1] <= s: dp.append(dp[-1] + w) for i in range(sz - 1)[::-1]: if dp[i] <= s: dp[i + 1] = min(dp[i + 1], dp[i] + w) print(len(dp) - 1)