#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, b;
  string s;
  vector<pair<string, int>> c;
  cin >> n;
  map<string, int> a;
  for (int i = 0; i < n; i++) {
    cin >> s >> b;
    c.push_back(make_pair(s, b));
    if (a.find(s) == a.end()) {
      a[s] = b;
    } else
      a[s] += b;
  }
  int max = -100001;
  for (map<string, int>::iterator it = a.begin(); it != a.end(); it++) {
    if ((*it).second > max) max = (*it).second;
  }
  map<string, int> d;
  for (int i = 0; i < n; ++i) {
    if (a[c[i].first] == max) {
      d[c[i].first] += c[i].second;
      if (d[c[i].first] >= max) {
        cout << c[i].first;
        break;
      }
    }
  }
  return 0;
}
