#include <bits/stdc++.h>
bool letter(char x) { return x >= 'a' && x <= 'z'; }
void solve(int n) {
  int i, j, q[1010], w[1010];
  char c[40], x;
  std::string s, ss[1010];
  gets(c);
  std::map<std::string, int> m;
  std::map<std::string, int>::iterator it;
  for (i = 0; i < n; i++) {
    s = "";
    while (letter(x = getchar())) s += x;
    scanf("%d", &j);
    m[s] += j;
    ss[i] = s;
    q[i] = m[s];
    gets(c);
  }
  j = m.begin()->second;
  for (it = m.begin(); it != m.end(); it++)
    if (it->second > j) j = it->second;
  for (i = 0; i < n; i++)
    if (m[ss[i]] == j && q[i] >= j) {
      printf("%s\n", ss[i].c_str());
      return;
    }
}
int main() {
#pragma comment(linker, "/STACK:134217728")
  int n, m;
  while (scanf("%d", &n) != EOF) {
    solve(n);
  }
  return 0;
}
