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

#define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll            long long
#define t()           int t;cin>>t;while(t--)
#define lt()          long long int t;cin>>t;while(t--)
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair   
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define all(x)              begin(x),end(x)
#define  nik(i,k,n)    for ( long long int i = k; i < (n); ++i)

void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
ll gcd(ll A , ll B)
{
  if(B == 0)return A;
  return gcd(B , A%B);
}
ll fact(ll n){
   ll ans = 1;
   for(ll i=1;i<=n;i++){
      ans*=i%mod;
   }
   return ans%mod;
}

bool checkperfectsquare(int n)
{
    if (ceil((double)sqrt(n)) == floor((double)sqrt(n))) {
        return true;
    }
    return false;
}

bool isPowerOfTwo(ll n)
{
    if (n == 0)
        return 0;
    while (n != 1)
    {
        if (n%2 != 0)
            return 0;
        n = n/2;
    }
    return 1;
}

void fast()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}

char s[500005];


void solve()
{
    int n;
    cin >> n;
    vector<pair<int, string > > v;
    vector<int> t;
    while(n--){
        string s;
        int h;
        cin >> s >> h;
        t.pb(h);
        v.push_back({h , s});
    }
    sort(t.rbegin() , t.rend());

    int x  = t[1];

    for(auto p : v){
        if(p.first == x){
            cout << p.second << endl;

        } 
    }

}  
int32_t main()
{
   IOS;
   //lt(){
      solve();
   //}
   return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int Read()
{
    int Output=0;
    char Input=getchar();
    while(Input<'0'||Input>'9')
    Input=getchar();
    while(Input>='0'&&Input<='9')
    {
        Output=Output*10+Input-'0';
        Input=getchar();
    }
    return Output;
}
int N;
char Name[1001][16];
int T[1001];
int Max,Sec;
int main()
{
	N=Read();
	for(int i=1;i<=N;++i)
	{
		scanf("%s",Name[i]);
		T[i]=Read();
		if(T[i]>T[Max])
		{
			Sec=Max;
			Max=i;
		}
		else if(T[i]>T[Sec])
		Sec=i;
	}
	printf("%s",Name[Sec]);
}