import sys input = sys.stdin.readline N = int(input()) a = [tuple(map(int, input().split())) for _ in range(N)] a.sort(key = lambda x: (x[1], x[0])) inf = 10 ** 9 * N dp = [inf] * (N + 1) dp[0] = 0 for i in range(N): w, s = a[i] for i in range(N - 1, -1, -1): if dp[i] <= s: dp[i + 1] = min(dp[i + 1], dp[i] + w) for i in range(N, -1, -1): if dp[i] < inf: print(i) break