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) for _ in range(n + 1)] dp[0][0] = 0 for t in range(n): w, s = ws[t] dp[t + 1][0] = 0 for i in range(n, 0, -1): if dp[t][i - 1] <= s: dp[t + 1][i] = min(dp[t][i], dp[t][i - 1] + w) else: dp[t + 1][i] = dp[t][i] for i in range(n, 0, -1): if dp[n][i] != 1 << 60: print(i) break