#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
map<string, int> mp1;
int main() {
  int n;
  cin >> n;
  int mx = 0;
  vector<pair<string, int>> v;
  set<string> st;
  for (int i = 0; i < n; i++) {
    string s;
    int a;
    cin >> s >> a;
    st.insert(s);
    v.push_back({s, a});
    mp[s] = mp[s] + a;
  }
  for (auto it : st) mx = max(mx, mp[it]);
  string res;
  for (int i = 0; i < v.size(); i++) {
    string s = v[i].first;
    int x = v[i].second;
    mp1[s] = mp1[s] + x;
    if (mp1[s] >= mx && mp[s] == mx) {
      res = s;
      break;
    }
  }
  cout << res << endl;
}
