#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[1004][40];
  int sco[1004], n;
  cin >> n;
  for (int h = 1; h <= n; h++) {
    map<string, int> nama, temp;
    int res = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i] >> sco[i];
      nama[s[i]] += sco[i];
    }
    for (int i = 0; i < n; i++) {
      if (nama[s[i]] > res) res = nama[s[i]];
    }
    for (int i = 0; i < n; i++) {
      if (nama[s[i]] == res) temp[s[i]] += sco[i];
      if (temp[s[i]] >= res) {
        puts(s[i]);
        break;
      }
    }
    return 0;
  }
}
