#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define int unsigned int
//#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
//#define lb lower_bound
//#define ub upper_bound
//#define bs binary_search
#define mod 1000000007 // mod+2
#define double long double
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
const int inf=1e18;
const int maxu=200005;
//int d;
//vector <int> adj[maxu];  
//vector <int> vis(maxu);
//vector <vector <int>> v(maxu);

/*
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}

int fun(int a,int b){
    if(b==0)return 1;
    else if(a==1)return 1;
    int temp=fun(a,b/2)%mod;
    temp=(temp*temp)%mod;
     if(b%2==1)temp=(temp*a)%mod;
    return temp%mod;
}
 
int inv(int a,int b){
    return (a*fun(b,mod-2))%mod;
}

void dfs(int s){
    if(vis[s])return;
    vis[s]=1;
    for(auto u:adj[s]){
        dfs(u);
    }
}*/

 
signed main()
{   /*  
   #ifndef ONLINE_JUDGE 
   freopen("inputhsr.txt", "r", stdin);  
   freopen("outputhsr.txt", "w", stdout); 
   #endif 
   */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int i,j,k=0,n,t=1,m,l=0;
    
    
    
    //cin>>t;
    while(t--){
        cin>>n;
        vector <pair<int,string>> v(n);
        for(i=0;i<n;i++){
            cin>>v[i].second>>v[i].first;
            v[i].first*=-1;
        }
        
        sort(all(v));
        
        cout<<v[1].second<<"\n";
        /*
       for(i=0;i<=n;i++)vis[i]=0;
       for(i=0;i<=n;i++){
            adj[i].clear();
       }
       */
       
        /*string s;
        cin>>s;
        n=s.length();*/

        //memset(a,0,sizeof(a));
        //cout<<fixed<<setprecision(10)<<ans<<"\n";
       
    }
    return 0;
}


#include <iostream>                                                             
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;


using namespace std;

int main() {



        int n;
        cin >> n;
        int t[n];
        string s[n];
        string a="string";
        string ans;
        int b=-1;
        int c=-1;
        rep(i,n){
            cin >> s[i] >> t[i];
           if(i==0){
                   b=t[i];
                   a=s[i];
           } else if(i>0 && b<t[i]){
                   c=b;
                   b=t[i];
                   ans=a;
                   a=s[i]; 
           }else if(c<t[i]&&b>t[i]){
                   c=t[i];
                   ans=s[i];
           }
        }

cout << ans << endl;




    return 0;
}