#include <bits/stdc++.h>
using namespace std;
struct pace {
  string name;
  int score;
};
struct pace paces[1005];
int pace_num;
int main() {
  pace_num = 0;
  int n;
  scanf("%d", &n);
  char name[35];
  int score;
  map<string, int> name_score;
  for (int i = 0; i < n; i++) {
    scanf("%s %d", name, &score);
    paces[pace_num].name = name;
    paces[pace_num].score = score;
    pace_num++;
    if (name_score.find(name) == name_score.end()) name_score[name] = 0;
    name_score[name] += score;
  }
  int max_score = -1;
  for (map<string, int>::iterator itr = name_score.begin();
       itr != name_score.end(); itr++) {
    max_score = max_score >= itr->second ? max_score : itr->second;
  }
  map<string, bool> max_mans;
  for (map<string, int>::iterator itr = name_score.begin();
       itr != name_score.end(); itr++) {
    if (itr->second == max_score) max_mans[itr->first] = true;
  }
  int min_pace = 1009;
  string winner;
  name_score.clear();
  for (int i = 0; i < pace_num; i++) {
    if (max_mans.find(paces[i].name) != max_mans.end()) {
      if (name_score.find(paces[i].name) == name_score.end())
        name_score[paces[i].name] = 0;
      name_score[paces[i].name] += paces[i].score;
      if (name_score[paces[i].name] >= max_score) {
        winner = paces[i].name;
        goto WINNER_GOT;
      }
    }
  }
WINNER_GOT:
  printf("%s\n", winner.c_str());
  return 0;
}
