import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable long inf = 10L^^15;

void main() {
    int n;
    scan(n);

    auto h = new int[](n);
    auto p = new int[](n);
    auto hp = new int[](n);

    foreach (i ; 0 .. n) {
        scan(h[i], p[i]);
        hp[i] = h[i] + p[i];
    }

    sort(zip(hp, h, p));

    debug {
        writeln(hp);
        writeln(h);
        writeln(p);
    }

    auto dp = new long[][](n + 1, n + 1);
    fillAll(dp, inf);
    dp[0][0] = 0;

    foreach (i ; 1 .. n + 1) {
        foreach (j ; 0 .. n + 1) {
            dp[i][j] = dp[i-1][j];

            if (j-1 >= 0 && dp[i-1][j-1] <= h[i-1]) {
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + p[i-1]);
            }
        }
    }

    debug {
        writefln("%(%(%s %)\n%)", dp);
    }

    int ans;

    foreach (i ; 1 .. n + 1) {
        if (dp[n][i] < inf) ans = i;
    }

    writeln(ans);

}



struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
        }
        else {
            p[v] = u;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}