#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<pair<string, long long> > t;
  vector<bool> check;
  cin >> n;
  long long max = -2000;
  char in[34];
  int val;
  for (int i = 0; i < n; i++) {
    scanf("%s", in);
    cin >> val;
    t.push_back(make_pair(string(in), val));
    check.push_back(true);
    for (int j = i - 1; j >= 0; j--) {
      if (t[i].first == t[j].first) {
        t[i].second += t[j].second;
        check[j] = false;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (check[i] == true) {
      if (t[i].second > max) max = t[i].second;
    }
  }
  int imin = 2000;
  for (int i = 0; i < n; i++) {
    if (check[i] == true && t[i].second == max) {
      for (int j = 0; j <= i; j++) {
        if (t[j].second >= max && t[j].first == t[i].first) {
          if (j < imin) imin = j;
          break;
        }
      }
    }
  }
  cout << t[imin].first;
  return 0;
}
