#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, i, score, mx_score = -100000;
  string name, winner;
  map<string, int> mp1, mp2;
  cin >> n;
  vector<pair<string, int>> input(n);
  for (i = 0; i < n; i++) cin >> input[i].first >> input[i].second;
  for (i = 0; i < n; i++) {
    name = input[i].first;
    score = input[i].second;
    mp1[name] += score;
  }
  for (auto i : mp1)
    if (i.second > mx_score) mx_score = i.second;
  for (i = 0; i < n; i++) {
    name = input[i].first;
    score = input[i].second;
    mp2[name] += score;
    if (mp2[name] >= mx_score && mp1[name] == mx_score) {
      winner = name;
      break;
    }
  }
  cout << winner << '\n';
  return 0;
}
