mod = 1000000007 eps = 10**-9 def main(): import sys from bisect import bisect_left input = sys.stdin.readline N = int(input()) WS = [] for _ in range(N): WS.append(tuple(map(int, input().split()))) WS.sort(key=lambda x: x[0] + x[1]) LIS = [0] for w, s in WS: j = bisect_left(LIS, s+1) if j == len(LIS): LIS.append(LIS[-1] + w) for k in range(j-1, 0, -1): LIS[k] = min(LIS[k], LIS[k-1] + w) else: for k in range(j, 0, -1): LIS[k] = min(LIS[k], LIS[k-1] + w) print(len(LIS) - 1) if __name__ == '__main__': main()