#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a. end())
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<ll>> vvll;
typedef long double ld;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n),t1(n);
    rep(i,n){
        cin >> s[i]>>t[i];
    }
    t1=t;
    Sort(t1);
    Reverse(t1);
    int second=t1[1];
    rep(i,n){
        if (t[i]==second){
            cout<<s[i];
            return 0;
        }
    }


}
    
/* Up : 1 2 0 5 - 201 */

#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

#include <vector>
#include <iomanip>
#include <time.h>


#define file    freopen("input.txt","r",stdin)
#define ll      long long int
#define space   printf(" ")
#define newline printf("\n")

using namespace std;


ll cs()
{
    ll n;
    scanf("%lld",&n);
    return n;
}
void cp(ll i)
{
    printf("%lld",i);
}




void test_case()
{
    /* start here for test case prob */

    ll n;
    n = cs();
    ll a[n],b[n];
    string s[n];
    getchar();
    for(ll i=0 ; i<n ; i++)
    {
        cin >> s[i];
        cin >> a[i];
        b[i] = a[i];
        getchar();
    }

    sort(b,b+n);
    for(ll i=0 ; i<n ; i++)
    {
        if(b[n-2]==a[i])
        {
            cout << s[i] << endl;
        }
    }



}
void t()
{
    ll tc;
    tc = cs();
    while(tc--)
    {
        test_case();
    }
}




int main()
{
    //file;
    test_case();
    //t();







    return 0;
}


