import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Block[] blocks = new Block[n]; for (int i = 0; i < n; i++) { blocks[i] = new Block(sc.nextInt(), sc.nextInt()); } Arrays.sort(blocks); long[][] dp = new long[n + 1][n + 1]; for (long[] arr : dp) { Arrays.fill(arr, Long.MAX_VALUE / 2); } dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= i; j++) { dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]); if (dp[i - 1][j - 1] <= blocks[i - 1].limit) { dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - 1] + blocks[i - 1].weight); } } } for (int i = n; i >= 0; i--) { if (dp[n][i] < Long.MAX_VALUE / 2) { System.out.println(i); return; } } } static class Block implements Comparable { int weight; int limit; public Block(int weight, int limit) { this.weight = weight; this.limit = limit; } public int compareTo(Block another) { return - another.weight - another.limit + weight + limit; } public String toString() { return weight + ":" + limit; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }