#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
int main() {
  long long int N, lrg = -1e18;
  cin >> N;
  string res = "";
  map<string, long long int> mp, tmp;
  string S[10000];
  long long int X[10000];
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> X[i];
    mp[S[i]] += X[i];
  }
  for (int i = 0; i < N; i++) {
    lrg = max(lrg, mp[S[i]]);
  }
  for (int i = 0; i < N; i++) {
    tmp[S[i]] += X[i];
    if (tmp[S[i]] >= lrg && mp[S[i]] >= lrg) {
      cout << S[i] << '\n';
      return 0;
    }
  }
  return 0;
}
