#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
#include<bitset>
using namespace std;

void solve() {
	int n;
	cin >> n;
	vector<pair<int, string>> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i].second;
		cin >> a[i].first;
	}
	sort(a.begin(), a.end());
	cout << a[n - 2].second << endl;
}
 
int main () {
	int t = 1;
	for(int tt = 0; tt < t; tt++) solve();
	return 0;
}

#include <iostream>
using namespace std;
int a[1000],n;
string s[1000];
int t[1000];
void partition(int *A, int n, int a, int *left,int *right);
void quicksort(int *A, int n);
int main() {
    
    for(int i =0;i<1000;i++){
        a[i]=i;
    }
    cin >> n;
    for(int i=0;i<n;i++)cin >> s[i] >> t[i];
    quicksort(a, n);
    printf("%s\n",(s[a[1]]).c_str());
    
    return 0;
}

void quicksort(int *A, int n) {
  if(n>1) {
      int b; b=t[A[0]];
    int left,right;
    partition(A,n,b,&left,&right);
    quicksort(A,right+1);
    quicksort(&A[left],n-left);
  }
}
void partition(int *A, int n, int a, int *left,int *right)
{
                                                                      
    *left = 0;*right = n-1;
    while(*left<=*right){
        while(t[A[*left]]>a){
            *left = *left + 1;
        }
        while(t[A[*right]]<a){
            *right = *right - 1;
        }
        if(*left<=*right){
            int temp = A[*right];
            A[*right]=A[*left];
            A[*left]=temp;
            *left = *left + 1;*right = *right - 1;
            
        }
    }
                                                                      
}

