#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i=((n)-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<pair<int,string>> vp;
    rep(i,n){
        string s;
        int a;
        cin>>s>>a;
        vp.push_back({a,s});
    }
    sort(all(vp));
    cout<<vp[n-2].second;
}
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
using namespace std;

inline void yn(bool a){cout<<(a?"YES":"NO");}

void solve() {
    int n;cin>>n;
    vector<pair<string,int>>v(n);
    for(int i=0;i<n;i++)cin>>v[i].fi>>v[i].se;
    sort(v.begin(),v.end(),[&](pair<string,int>a,pair<string,int>b){
        return a.se>b.se;
    });
    cout<<v[1].fi;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tc=1;//cin>>tc;
    for (int t = 1; t <= tc; t++) {
        //cout<<"Case #"<<t<<" : ";
        solve();
        cout<<'\n';
    }
}