def main(): N = int(input()) Z = [] for i in range(N): w,s = map(int,input().split()) Z.append((w,s)) Z.sort(key = lambda x: x[0] + x[1]) ans = 0 weight = 0 for i in range(N): w,s = Z[i] if weight <= s: ans += 1 weight += w print(ans) if __name__ == '__main__': main()