#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  map<string, int> data;
  map<string, int>::iterator p;
  int i, n, x;
  cin >> n;
  int ara[n];
  string str[n];
  for (i = 0; i < n; i++) {
    cin >> s >> x;
    ara[i] = x;
    str[i] = s;
    p = data.find(s);
    if (p == data.end()) {
      data[s] = x;
    } else {
      data[s] += x;
    }
  }
  p = data.begin();
  int maximum = -10000000;
  while (p != data.end()) {
    if (p->second > maximum) maximum = p->second;
    p++;
  }
  p = data.begin();
  map<string, int> winners;
  while (p != data.end()) {
    if (p->second == maximum) {
      winners[p->first] = 0;
      s = p->first;
    }
    p++;
  }
  int len;
  len = winners.size();
  if (len == 1) {
    cout << s << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    p = winners.find(str[i]);
    if (p != winners.end()) {
      p->second += ara[i];
      if (p->second >= maximum) {
        cout << p->first << endl;
        return 0;
      }
    }
  }
  return 0;
}
