#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  map<string, int> players, players1;
  vector<pair<string, int> > order;
  string str, winner;
  int num, Max = -1;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str >> num;
    players[str] += num;
    order.push_back(make_pair(str, num));
  }
  for (map<string, int>::const_iterator it = players.begin();
       it != players.end(); it++)
    if (it->second > Max) Max = it->second;
  for (int i = 0; i < order.size(); i++) {
    players1[order[i].first] += order[i].second;
    if (players1[order[i].first] >= Max) {
      for (map<string, int>::const_iterator it = players.begin();
           it != players.end(); it++)
        if ((it->first == order[i].first) && (it->second == Max)) {
          cout << order[i].first;
          return 0;
        }
    }
  }
  return 0;
}
