#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::string;
int n = 0, l_read = 0;
string cur_p_name;
int cur_p_score;
struct p_scr {
  string name;
  int score = 0;
} p_scr[1000];
int final_p_i = 0;
int p_num = 0;
map<string, int> p_score_first_thought;
map<string, int> p_score_final_thought;
map<string, int> is_p_winner;
int m;
string winner;
int main() {
  cin >> n;
  while (l_read != n && cin >> cur_p_name >> cur_p_score) {
    p_scr[l_read].name = cur_p_name;
    p_scr[l_read].score = cur_p_score;
    p_score_first_thought[cur_p_name] += cur_p_score;
    l_read++;
  }
  map<string, int>::iterator iter = p_score_first_thought.begin();
  m = iter->second;
  iter++;
  while (iter != p_score_first_thought.end()) {
    m = max(m, iter->second);
    iter++;
  }
  iter = p_score_first_thought.begin();
  while (iter != p_score_first_thought.end()) {
    is_p_winner[iter->first] = iter->second == m ? 1 : 0;
    iter++;
  }
  while (final_p_i != l_read) {
    if (is_p_winner[p_scr[final_p_i].name]) {
      p_score_final_thought[p_scr[final_p_i].name] += p_scr[final_p_i].score;
      if (p_score_final_thought[p_scr[final_p_i].name] >= m) {
        winner = p_scr[final_p_i].name;
        break;
      }
    }
    final_p_i++;
  }
  cout << winner;
  return 0;
}
