#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  string st[n];
  int score[n];
  int maxi = INT_MIN;
  map<string, int> check;
  map<string, int> check2;
  map<string, int>::iterator p;
  for (int i = 0; i < n; i++) {
    cin >> st[i] >> score[i];
    check[st[i]] = check[st[i]] + score[i];
  }
  for (p = check.begin(); p != check.end(); p++) {
    if (maxi < p->second) maxi = p->second;
  }
  int i = 0;
  for (i = 0; i < n; i++) {
    if (!((check[st[i]] < maxi) || (check2[st[i]] += score[i]) < maxi)) break;
  }
  cout << st[i];
}
