#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, l, n) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define def (200007)
#define MOD (1000000007)
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef int64_t intt;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<int, int> P;
/*veci のときdist.resize(N) Veciのとき2回resize;
dp.assign(N,-1);*/

int main(){
  int n;
  cin>>n;
  vector<string> name;
  int at_max=0;int at_i=0;int second_max=0,second_i=0;
  rep(i,0,n){
    string s;int t;
    cin>>s>>t;
    if(at_max<t){
      second_max=at_max;
      at_max=t;
      second_i=at_i;
      at_i=i;
     }else if(second_max<t){
      second_max=t;
      second_i=i;
    }
    name.push_back(s);
  }
  cout<<name[second_i]<<endl;
    
    
  
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ll long long
#define ld long double

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n; cin >> n;
	vector<pair<int, int>>arr;
	map<int, string>kode;
	int cur=0;
	for(int i=0;i<n;++i){
		string s; int x;
		cin >> s >> x;
		kode[cur]=s;
		arr.pb({x, cur});
		cur++;
	}
	sort(arr.begin(), arr.end(), greater<pair<int, int>>());
	cout << kode[arr[1].se] << '\n';
}
