#include <bits/stdc++.h>
using namespace std;
int gen(pair<string, int> re[1001], int len, string name, int score) {
  for (int i = (int)0; i < (int)len; i++) {
    if (re[i].first == name) {
      re[i].second += score;
      return re[i].second;
    }
  }
}
int finalscore(map<string, int> mx, string name) {
  for (typeof((mx).begin()) i = (mx).begin(); i != (mx).end(); i++) {
    if ((*i).first == name) return (*i).second;
  }
}
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  map<string, int> scores, re;
  int score[n];
  string name[n];
  for (int i = (int)0; i < (int)n; i++) {
    cin >> name[i] >> score[i];
    scores[name[i]] += score[i];
  }
  int best;
  best = -1;
  for (typeof((scores).begin()) i = (scores).begin(); i != (scores).end(); i++)
    if ((*i).second > best) best = (*i).second;
  for (int i = (int)0; i < (int)n; i++) {
    re[name[i]] += score[i];
    if (re[name[i]] >= best && scores[name[i]] == best) {
      cout << name[i];
      return 0;
    }
  }
  return 0;
}
