#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, ans = 0;
  string res = "";
  unordered_map<string, long long int> m;
  unordered_map<string, long long int> mp;
  set<string> sat;
  cin >> t;
  long long int a[t], i = 0;
  string s[t];
  for (int i = 0; i < t; i++) {
    cin >> s[i];
    cin >> a[i];
    m[s[i]] += a[i];
  }
  for (auto x : m) {
    ans = max(x.second, ans);
  }
  for (auto x : m) {
    if (x.second == ans) {
      sat.insert(x.first);
    }
  }
  if (sat.size() == 1) {
    auto a = sat.begin();
    cout << *a;
  } else {
    for (int j = 0; j < t; j++) {
      mp[s[j]] = mp[s[j]] + a[j];
      if (mp[s[j]] >= ans && sat.find(s[j]) != sat.end()) {
        res = s[j];
        break;
      }
    }
    cout << res;
  }
}
