#include <cstdio>
#include <algorithm>
using namespace std;
struct str{
	int t;
	char *s;
	bool operator<(const str &b)const{
		return t>b.t; 
	}
};
int n;
str mon[1003];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		mon[i].s=new char;
		scanf("%s%d",mon[i].s,&mon[i].t);
	}
	sort(mon,mon+n);
	printf("%s\n",mon[1].s);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,m,n) for (int i = (m); i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n; cin >> n;
  vector<pair<int, string>> v;
  rep(i,n) {
    int t;
    string s;
    cin >> s >> t;
    v.emplace_back(t, s);
  } 

  sort(rall(v));

  cout << v[1].second << endl;
}
