#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> a;
  int n;
  cin >> n;
  int n0 = n;
  int mna[1024];
  string na[1024];
  string te;
  int max0 = -1;
  int tenu;
  for (int i = 0; i < n; i++) {
    cin >> na[i] >> mna[i];
    a[na[i]] += mna[i];
  }
  map<string, int>::iterator it;
  for (it = a.begin(); it != a.end(); it++) {
    if (it->second > max0) max0 = it->second;
  }
  map<string, int> as;
  for (int i = 0; i < n; i++) {
    as[na[i]] += mna[i];
    if (as[na[i]] >= max0 && a[na[i]] == max0) {
      cout << na[i] << endl;
      break;
    }
  }
  return 0;
}
