#include <bits/stdc++.h>
const double eps = 1e-3;
const double PI = 3.1415926535897932384626433832795;
const int maxn = 9999999;
using namespace std;
char name[1001][40];
int grade[1001];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    map<string, int> mp;
    for (int i = 1; i <= n; i++) {
      scanf("%s %d", name[i], &grade[i]);
      mp[name[i]] += grade[i];
    }
    int max = -9999999;
    for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
      if (it->second > max) max = it->second;
    map<string, int> mp2;
    for (int i = 1; i <= n; i++) {
      mp2[name[i]] += grade[i];
      if (mp[name[i]] == max && mp2[name[i]] >= max) {
        puts(name[i]);
        break;
      }
    }
  }
  return 0;
}
