#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  string s;
  int p, mx = -10000000;
  vector<string> v;
  vector<int> vp;
  int ps[n + 1];
  int t = n;
  for (int i = 0; i <= n; i++) ps[i] = 1;
  while (t--) {
    cin >> s >> p;
    v.push_back(s);
    vp.push_back(p);
  }
  vector<string> w;
  vector<int> wp;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    if (ps[i]) {
      string a = v[i];
      w.push_back(a);
      for (int j = i; j < n; j++) {
        if (v[j] == a) {
          cnt += vp[j];
          ps[j] = 0;
        }
      }
      wp.push_back(cnt);
    }
  }
  int l = wp.size();
  for (int i = 0; i < l; i++) mx = max(mx, wp[i]);
  vector<string> win;
  vector<int> wc;
  for (int i = 0; i < l; i++) {
    if (wp[i] == mx) {
      win.push_back(w[i]);
      wc.push_back(0);
    }
  }
  int sz = win.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < sz; j++) {
      if (v[i] == win[j]) {
        wc[j] += vp[i];
        if (wc[j] >= mx) {
          cout << win[j] << "\n";
          return 0;
        }
        break;
      }
    }
  }
}
