#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string ans;
  int i = 0;
  map<string, int> mp, mp2;
  string na[1000];
  int sc[1000];
  for (i = 0; i < n; i++) {
    cin >> na[i] >> sc[i];
    mp[na[i]] += sc[i];
  }
  int max_v = 0;
  i = 0;
  while (i < n) {
    max_v = max(max_v, mp[na[i]]);
    i++;
  }
  i = 0;
  while (i < n) {
    mp2[na[i]] += sc[i];
    if (mp[na[i]] == max_v && mp2[na[i]] >= max_v) {
      cout << na[i] << endl;
      break;
    }
    i++;
  }
  return 0;
}
