    /* Great things never come from comfort zones,
    "whatever the mind of a man can conceive and believe,it can achieve." */
     
    #include <bits/stdc++.h>
    using namespace std;
 
    void my_dbg() { cout << endl; }
    template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
    { cout << ' ' << A; my_dbg(B...); }
    #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
 
    #define ll long long
    #define dd double
    #define scf(n) scanf("%d",&n)
    #define lscf(n) scanf("%lld",&n)
    #define lpri(n) printf("%lld ",n)
    #define pri(n) printf("%d ",(int)n)
    #define prin(n) printf("%d\n",(int)n)
    #define lprin(n) printf("%lld\n",n)
    #define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
    #define show(a) for(auto xy: a) pri(xy); printf("\n");
 
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define all(x)     x.begin(),x.end()
    #define SET(a,b) memset(a,b,sizeof(a))
    #define tc   int tt; scf(tt); while(tt--)
 
    #define inf INT_MAX
    #define ninf INT_MIN
    #define gcd __gcd
    #define bitcount(n) __builtin_popcount(n)
 
    const int mod=1e9+7;
    const int N = 1e6+7;

    int pos[N];

    int main()
    {
        int n; scf(n);

        vector<ll>a(n),b(n);

        vector<int>ind(n);

        iota(all(ind),0);// iterates and fill with increaing values
                        //0 1 2 3 4.......


        ll A=0,B=0,tmp;

        rep(i,0,n)
        lscf(a[i]),lscf(b[i]);

        sort(all(ind),[&](const int &i , const int &j)
        {
            return (2*a[i]+b[i]>2*a[j]+b[j]);
        }); // net effect 2*a[k] + b[k] in town of speech 

        A=accumulate(all(a),0ll);

        int c=0,d=0;

        rep(i,0,n)
        {
            if(B>A)
            break;

            c++;

            int j=ind[i];

            B+=b[j]+a[j];

            A-=a[j];
        }

        prin(c);

    }
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define veci vector<int> 
#define vecll vector<ll>
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x, start, end) for (auto x = (start) - ((start) > (end)); x != (end) - ((end) < (start)); ((start) < (end) ? x++ : x--))
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);

    int a, b;
    cin >> a >> b;
    int c = a + b;
    
    if (c >= 15 && b >= 8)
        cout << 1 << endl;
    else if (c >= 10 && b >= 3)
        cout << 2 << endl;
    else if (c >= 3)
        cout << 3 << endl;
    else
        cout << 4 << endl;

    return 0;
    return 0; 
}