#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int sc, n, mx = -2000, i;
  string name, ans;
  map<string, int> mp;
  map<string, int> mp1;
  cin >> n;
  vector<pair<string, int>> a(n);
  for (i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
    mp[a[i].first] += a[i].second;
  }
  for (auto x : mp) mx = max(x.second, mx);
  for (i = 0; i < n; ++i) {
    mp1[a[i].first] += a[i].second;
    if (mp1[a[i].first] >= mx && mp[a[i].first] == mx) {
      cout << a[i].first;
      return 0;
    }
  }
}
