#include<bits/stdc++.h>
#define int long long int
using namespace std;

signed main(){
   // freopen("input.txt", "r", stdin);
    map<int, string> m;
    int n, a, c;
    string b;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>b>>a;
        m[a]=b;
    }
    a=1;
    for(auto i=m.rbegin(); i != m.rend(); i++ ){
        if(a==2){
            cout<<i->second<<endl;
            return 0;
        }
        a++;
    }
    return 0;
}
#include<algorithm>
#include<iostream>
#include<vector>
#define mp make_pair
#define pb push_back

#define fo(i,n) for(int i=0;i<(n);i++)
using namespace std;




void solve(){
    int n;
    cin>>n;
    vector<pair<int ,string>> names(n);
    fo(i,n){
        cin>>names[i].second>>names[i].first;
    }
    sort(names.begin() , names.end());
    cout<<names[n-2].second;

}

int main() {
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
