#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long inf = INT_MAX;
long long m_inf = INT_MIN;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.setf(std::ios::fixed, std::ios::floatfield);
  std::cout.precision(6);
  long long n;
  cin >> n;
  pair<string, long long> p[n];
  for (long long i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  map<string, long long> m;
  for (long long i = 0; i < n; i++) {
    m[p[i].first] += p[i].second;
  }
  map<string, long long>::iterator it;
  long long mx = m_inf;
  string winner;
  long long count = 0;
  for (it = m.begin(); it != m.end(); it++) {
    if ((it->second) > mx) {
      mx = it->second;
      winner = it->first;
      count = 1;
    } else if ((it->second) == mx) {
      count++;
    }
  }
  if (count == 1) {
    cout << winner << '\n';
    return 0;
  }
  map<string, long long> m2;
  for (long long i = 0; i < n; i++) {
    m2[p[i].first] += p[i].second;
    if (m2[p[i].first] >= mx && m[p[i].first] == mx) {
      winner = p[i].first;
      break;
    }
  }
  cout << winner << '\n';
}
