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