#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, a, mx = 0;
  string s, g;
  vector<pair<string, long long int>> v;
  map<string, long long int> mp;
  map<string, long long int>::iterator itr;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s >> a;
    v.push_back(make_pair(s, a));
    mp[s] += a;
  }
  for (itr = mp.begin(); itr != mp.end(); itr++) {
    mx = max(mx, itr->second);
  }
  map<string, long long int> mp1, mp2;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    if (i->second == mx) mp1[i->first] = 1;
  }
  for (int i = 0; i < v.size(); i++) {
    mp2[v[i].first] += v[i].second;
    if (mp2[v[i].first] >= mx && mp1[v[i].first] == 1) {
      cout << v[i].first;
      exit(0);
    }
  }
  return 0;
}
