#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  ll N;
  cin>>N;
  vector<pair<int,string>> A(N);
  rep(i,N){
   cin>>A[i].second>>A[i].first;
  }
  sort(all(A));
  cout<<A[N-2].second<<endl;
}
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> Vll;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    ll suma=0;;
    rep(i,n){
        cin  >> a[i] >> b[i];
        suma+=a[i];
    }

    priority_queue<ll> dif;
    rep(i,n){
        dif.push(2*a[i]+b[i]);
    }
    ll ans=0;
    rep(i,n){
        suma-=dif.top();
        dif.pop();
        ans++;
        if(suma<0)break;
    }
    cout << ans << endl;
}

