#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
map<string, int> m;
map<int, string> k;
int sc[maxn], sc2[maxn];
string inps[maxn];
int inpa[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> inps[i] >> inpa[i];
    if (m.find(inps[i]) == m.end()) {
      pair<string, int> tmp;
      pair<int, string> tmp1;
      tmp.first = inps[i];
      tmp.second = m.size();
      m.insert(tmp);
      tmp1.first = tmp.second;
      tmp1.second = tmp.first;
      k.insert(tmp1);
    }
    sc[m[inps[i]]] += inpa[i];
  }
  int x = 0, t = 0;
  string ans;
  for (int i = 0; i < m.size(); i++) {
    if (sc[i] > x) {
      ans = k[i];
      x = sc[i];
      t = 1;
    } else if (sc[i] == x)
      t++;
  }
  if (t == 1) {
    cout << ans << endl;
    return 0;
  } else {
    for (int i = 0; i < n; i++) {
      sc2[m[inps[i]]] += inpa[i];
      if (sc2[m[inps[i]]] >= x and sc[m[inps[i]]] >= x) {
        cout << inps[i] << endl;
        return 0;
      }
    }
  }
}
