#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int64_t n;
  cin >> n;
  vector<pair<string, int64_t>> v(n);
  for (int64_t i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  unordered_map<string, int64_t> map;
  for (int64_t i = 0; i < n; i++) map[v[i].first] = 0;
  unordered_map<string, int64_t> change[n];
  int64_t maxm = INT_MIN;
  for (int64_t i = 0; i < n; i++) {
    map[v[i].first] += v[i].second;
    change[i] = map;
    if (i == n - 1) {
      for (auto x : map) maxm = max(maxm, x.second);
    }
  }
  string ans = "";
  for (int64_t i = 0; i < n; i++) {
    bool found = false;
    for (auto x : change[i]) {
      if (x.second >= maxm && map[x.first] == maxm) {
        ans = x.first;
        found = true;
        break;
      }
    }
    if (found) break;
  }
  cout << ans << "\n";
  return 0;
}
