#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sc[1100], t[1100], maxsc[1100], num = 0;
  char name[1100][100];
  char curn[1100];
  int turn[1100], pl[1100];
  int cursc;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int flag = 0;
    scanf("%s", curn);
    cin >> cursc;
    for (int j = 0; j < num; ++j)
      if (strcmp(curn, name[j]) == 0) {
        pl[i] = j;
        turn[i] = cursc;
        sc[j] += cursc;
        if (maxsc[j] < sc[j]) {
          maxsc[j] = sc[j];
          t[j] = i;
        }
        flag = 1;
        break;
      }
    if (flag == 0) {
      pl[i] = num;
      turn[i] = cursc;
      strcpy(name[num], curn);
      maxsc[num] = cursc;
      sc[num] = cursc;
      t[num] = i;
      ++num;
    }
  }
  int curp;
  int newsc[1100], newt[1100];
  for (int i = 0; i < num; ++i) {
    newsc[i] = 0;
    newt[i] = -1;
  }
  for (int i = 0; i < n; ++i) {
    curp = pl[i];
    cursc = turn[i];
    int j = pl[i];
    newsc[j] += cursc;
    if (newsc[j] >= sc[j] && newt[j] == -1) {
      newt[j] = i;
    }
  }
  int ansi = 0;
  for (int i = 0; i < num; ++i) {
    if (sc[i] < sc[ansi]) continue;
    if (sc[i] == sc[ansi] && newt[i] > newt[ansi]) continue;
    ansi = i;
  }
  printf("%s", name[ansi]);
  return 0;
}
