#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string name;
  int score;
  vector<pair<string, int>> storage;
  storage.reserve(n);
  map<string, int> scoreTB;
  map<string, int> checkTB;
  vector<string> winner;
  for (int i = 0; i < n; ++i) {
    cin >> name >> score;
    storage.push_back(make_pair(name, score));
    (scoreTB.count(name) == 0) ? scoreTB[name] = score : scoreTB[name] += score;
  }
  int max = 0;
  for (auto iter = scoreTB.begin(); iter != scoreTB.end(); ++iter) {
    if (iter->second > max) max = iter->second;
  }
  for (auto iter = scoreTB.begin(); iter != scoreTB.end(); ++iter) {
    if (iter->second == max) winner.push_back(iter->first);
  }
  for (int i = 0; i < n; ++i) {
    name = storage.at(i).first, score = storage.at(i).second;
    (checkTB.count(name) == 0) ? checkTB[name] = score : checkTB[name] += score;
    for (int j = 0; j < winner.size(); ++j) {
      if (checkTB[winner.at(j)] >= max) {
        cout << winner.at(j) << endl;
        return 0;
      }
    }
  }
  return 0;
}
