#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool cmp(pair<string, int>& a,
         pair<string, int>& b)
{
    return a.second < b.second;
}
  
// Function to sort the map according
// to value in a (key-value) pairs
void sort(map<string, int>& M, int n)
{
  
    // Declare vector of pairs
    vector<pair<string, int> > A;
  
    // Copy key-value pair from Map
    // to vector of pairs
    for (auto& it : M) {
        A.push_back(it);
    }
  
    // Sort using comparator function
    sort(A.begin(), A.end(), cmp);
  	int i =0;
     for (auto& it : A) {
  		if(i==n-2){
        cout << it.first<<  endl;
             return;
        }
        i++;
    }
}
int main(){
	int n; cin >> n;
	map<string,int>  mountain;

	for(int i = 0; i < n; i++){
		string mount; cin >> mount;
		int height; cin >> height;
		mountain.insert(pair<string,int>(mount,height));
	}
	sort(mountain, n);

	 return 0;
}	


#include <bits/stdc++.h>
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define LOOP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define lp(i,n) LOOP(i,0,n)
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
int main(){
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n;
    scanf("%d", &n);
    char s[20];
    int h;
    int h1 = -1, h2 =-2;
    char s1[20], s2[20];
    lp(i,n){
        scanf(" %s %d", s, &h);
        if (h > h1){
            strcpy(s2, s1);
            strcpy(s1, s);
            h2 = h1;
            h1 = h;
        } else if (h > h2) {
            strcpy(s2, s);
            h2 = h;
        }
    }
    printf("%s", s2);
    return 0;
}
