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

int main() {
  int N;
  cin >> N;

  map<int, string> mountain;

  for (int i = 0; i < N; i++) {
    string S;
    int T;
    cin >> S >> T;
    mountain[T] = S;
  }

  auto no2 = mountain.end();
  advance(no2, -2);
  cout << no2->second << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;

void solve(){
  int n;
  cin >> n;
  string s;
  int t;
  priority_queue<pair<int,string> > memo;
  rep(i,n){
    cin >> s >> t;
    memo.push(make_pair(t,s));
  }
  memo.pop();
  cout << memo.top().second << endl;
    return;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  solve();
    return 0;
}