#include <bits/stdc++.h>
using namespace std;
string name[1010];
int score[1010];
bool good[1010];
map<string, int> mp;
int main(void) {
  int N, i;
  cin >> N;
  for ((i) = 0; (i) < (int)(N); (i)++) cin >> name[i] >> score[i];
  for ((i) = 0; (i) < (int)(N); (i)++) mp[name[i]] += score[i];
  int M = 0;
  for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++)
    M = max(M, (itr->second));
  for ((i) = 0; (i) < (int)(N); (i)++) good[i] = (mp[name[i]] == M);
  mp.clear();
  for ((i) = 0; (i) < (int)(N); (i)++) {
    mp[name[i]] += score[i];
    if (good[i] && mp[name[i]] >= M) break;
  }
  cout << name[i] << endl;
  return 0;
}
