#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
set<string> s;
string ss[200005];
int nu[200005], sc[200005];
int nu1[200005];
void solve() {
  ios::sync_with_stdio(false);
  memset(nu, 0, sizeof(nu));
  mp.clear();
  s.clear();
  int rt = 0, n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ss[i] >> sc[i];
    if (!s.count(ss[i])) {
      mp[ss[i]] = rt++, nu[rt - 1] += sc[i], s.insert(ss[i]);
    } else {
      nu[mp[ss[i]]] += sc[i];
    }
  }
  int Max = -1e9 + 9, pos, fflag = 0;
  for (int i = 0; i < rt; i++)
    if (nu[i] > Max) Max = nu[i];
  for (int i = 0; i < rt; i++) {
    if (nu[i] == Max) fflag++, pos = i;
  }
  if (fflag == 1) {
    map<string, int>::iterator it;
    for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second == pos) {
        cout << it->first << endl;
        return;
      }
    }
  }
  memset(nu1, 0, sizeof(nu1));
  for (int i = 0; i < n; i++) {
    nu1[mp[ss[i]]] += sc[i];
    if (nu1[mp[ss[i]]] >= Max && nu[mp[ss[i]]] == Max) {
      cout << ss[i] << endl;
      return;
    }
  }
}
int main() {
  solve();
  int mk;
  if (scanf("%d", &mk) == EOF) return 0;
  return 0;
}
