#include <bits/stdc++.h>
using namespace std;
vector<pair<string, int> >::iterator vit;
void search(string name, vector<pair<string, int> > v) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first == name) {
      vit = v.begin() + i;
      return;
    }
  }
  vit = v.end();
  return;
}
bool comp(pair<string, int> pr1, pair<string, int> pr2) {
  return pr1.second < pr2.second;
}
int main() {
  map<string, int> mp;
  vector<pair<string, int> > list, fin;
  fin.push_back(make_pair("-1", -1));
  string name;
  int score;
  int n, mx = -999999;
  cin >> n;
  while (n--) {
    cin >> name >> score;
    mp[name] += score;
    list.push_back(make_pair(name, mp[name]));
  }
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (it->second > mx) mx = it->second;
  }
  for (int i = 0; i < list.size(); i++) {
    if (list[i].second >= mx) {
      for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
        if (list[i].first == it->first && it->second == mx) {
          cout << it->first;
          return 0;
        }
      }
    }
  }
  return 0;
}
