#include <bits/stdc++.h>
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;
map<string, int> m;
map<string, int> p;
string name[1005];
int score[1005];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    cin >> name[i] >> score[i];
    m[name[i]] += score[i];
  }
  int mm = 0, cnt = 0;
  for (map<string, int>::iterator i = m.begin(); i != m.end(); i++) {
    if ((*i).second > mm) {
      mm = (*i).second;
      cnt = 0;
      p.clear();
      p[(*i).first] = 0;
    } else if ((*i).second == mm)
      p[(*i).first] = 0;
  }
  if (p.size() == 1)
    cout << (*p.begin()).first << endl;
  else {
    for (int i = 0; i < N; i++) {
      if (p.count(name[i])) {
        p[name[i]] += score[i];
        if (p[name[i]] >= mm) {
          cout << name[i] << endl;
          break;
        }
      }
    }
  }
  return 0;
}
