n = int(input()) ws = [list(map(int, input().split())) for i in range(n)] ws.sort(key=lambda x: x[0] + x[1]) dp = [[10 ** 18] * (n + 1) for i in range(n + 1)] dp[0][0] = 0 for i in range(1, n + 1): for j in range(n + 1): if j == 0: dp[i][j] = 0; continue if dp[i - 1][j - 1] > ws[i - 1][1]: dp[i][j] = dp[i - 1][j] else: dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + ws[i - 1][0]) for i in range(1, n + 1)[::-1]: if dp[n][i] != 10 ** 18: exit(print(i))