#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define even(x) (x % 2 == 0 ? true : false)
#define odd(x) (x % 2 ? true : false)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
//const int mod = 1000000007;
//vector<vector<int>> dp(m, vector<int>(n));

void	solve()
{
	int n;
	cin >> n;
	map<int, string> mp;
	for (int i = 0; i < n; i++) {
		string s;
		int t;
		cin >> s >> t;
		mp[t] = s;
	}
	int i = 0;
	for (auto p : mp) {
		i++;
		if (i == n - 1) {
			cout << p.second << endl;
			return ;
		}
	}
}

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	solve();
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  for(int i=0; i<N; i++) cin >> S.at(i) >> T.at(i);
  vector<int> t(N);
  for(int i=0; i<N; i++) t.at(i) = T.at(i);
  sort(t.begin(),t.end());
  int ans;
  for(int i=0; i<N; i++){
    if(T.at(i) == t.at(N-2)) ans = i;
  }
  cout << S.at(ans) << endl;
}