#include <bits/stdc++.h>
using namespace std;
map<string, int> ara;
int main() {
  (ios_base::sync_with_stdio(false), cin.tie(NULL));
  ;
  string str, ptr;
  int n, maximum = 0, k, m;
  cin >> n;
  vector<pair<string, int> > v;
  cin.ignore();
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> str >> m;
    v.push_back(make_pair(str, m));
    ara[str] += m;
  }
  map<string, int>::iterator it;
  for (it = ara.begin(); it != ara.end(); it++) {
    maximum = max(maximum, it->second);
  }
  string ktr[n + 1];
  k = 0;
  for (it = ara.begin(); it != ara.end(); it++) {
    if (it->second == maximum) {
      ptr = it->first;
      ktr[k++] = ptr;
    }
  }
  ptr.clear();
  if (k == 1)
    cout << ktr[0] << endl;
  else {
    bool c = false;
    map<string, int> cra;
    for (i = 0; i < n; i++) {
      c = false;
      for (j = 0; j < k; j++) {
        if (ktr[j] == v[i].first) {
          c = true;
          break;
        }
      }
      if (c) {
        cra[ktr[j]] += v[i].second;
        if (cra[ktr[j]] >= maximum) {
          ptr = v[i].first;
          break;
        }
      }
    }
    cout << ptr << endl;
  }
}
