#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  map<string, int> mp1;
  map<string, int> mp2;
  string name[1000];
  int score[1000];
  while (cin >> n) {
    int m = 0;
    for (i = 0; i < n; i++) {
      cin >> name[i] >> score[i];
      mp1[name[i]] += score[i];
    }
    for (i = 0; i < n; i++)
      if (mp1[name[i]] > m) m = mp1[name[i]];
    for (i = 0; i < n; i++) {
      mp2[name[i]] += score[i];
      if (mp2[name[i]] >= m && mp1[name[i]] == m) {
        cout << name[i] << endl;
        break;
      }
    }
  }
}
