#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>

using namespace std;

struct mountain
{
  string name;
  int height;
};

int main()
{
  int n;
  string input, most, second;
  long input_height, most_height, second_height;
  most_height = 0;
  second_height = 0;

  cin >> n;

  for (int i = 0; i < n; i++)
  {
    cin >> input >> input_height;
    if (i == 0)
    {
      most = input;
      most_height = input_height;
    }
    else if (most_height < input_height)
    {
      second = most;
      second_height = most_height;
      most = input;
      most_height = input_height;
    }
    else
    {
      if (second_height < input_height)
      {
        second = input;
        second_height = input_height;
      }
    }
  }
  cout << second << endl;

  return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define inF freopen("input.txt", "r", stdin);
#define outF freopen("output.txt", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";}cout << endl;
#define ld long double
#define PI 3.141592653589793238
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define int ll

void solve(){
    int n; cin >> n;
    vector<pair<int, string>> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first;
    }
    sort(all(v));
    cout << v[n - 2].second << endl;
}

int32_t main(){
    FAST
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
