#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string name[1003];
int score[1003];
int main() {
  int n, i, cnt = 0, j, mx = -0x3f3f3f3f;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> name[i] >> score[i];
    mp[name[i]] += score[i];
  }
  map<string, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++)
    if (it->second > mx) mx = it->second;
  for (it = mp.begin(); it != mp.end();) {
    if (it->second != mx)
      mp.erase(it++);
    else
      it++->second = 0;
  }
  for (i = 0; i < n; i++) {
    if (mp.find(name[i]) != mp.end()) {
      mp[name[i]] += score[i];
      if (mp[name[i]] >= mx) {
        cout << name[i] << endl;
        break;
      }
    }
  }
  return 0;
}
