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

int main(){
	int n;
	cin >> n;
	string s1,s2,sm;
	int t1=0,t2=0,tm;
	for(int i=0;i<n;i++){
		string s;
		int t;
		cin >> s >> t;
		if(t > t1){
			sm = s1;
			tm = t1;
			s1 = s;
			t1 = t;
			s2 = sm;
			t2 = tm;

		}
		else if(t > t2 && t < t1){
			s2 = s;
			t2 = t;
		}
	}

	cout << s2 << endl;

}



#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    pair<ll, string> p[N];
    string S;
    ll T;
    rep(i, 0, N){
        cin >> S >> T;
        p[i] = make_pair(T, S);
    }
    sort(p, p + N, greater<pair<ll, string>>());

    cout << p[1].second << endl;

    return 0;
}
