#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;
	string s[n];
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin >> s[i] >> a[i];
		b[i]=a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(b[i]==a[n-2]){
			cout << s[i] << endl;
		}
	}
	return 0;
}
#include<bits/stdc++.h>

using namespace std;




int main() {
	int n;
	cin >> n;
	int mx = -1;
	int prev = -1;
	map<int, string> m;
	while(n--) {
		string s;
		int temp;
		cin >> s ;
		cin >> temp;
		m[temp] = s;
		if(mx<temp){
			prev = mx;
			mx = temp;
		}
		
		else if(temp < mx && temp > prev)
			prev = temp;
	}
	
	cout << m[prev];
	
	
	return 0;
}
		
		