#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main(int argc, char** argv) {
  map<string, int> f, g;
  string s[1000];
  int c[1000], n;
  int i, m = 0;
  string h;
  cin >> n;
  for (i = 0; i < n; ++i) cin >> s[i] >> c[i], f[s[i]] += c[i];
  for (i = 0; i < n; ++i) {
    if (m < f[s[i]]) m = f[s[i]];
  }
  i = 0;
  for (i = 0; f[s[i]] < m || (g[s[i]] += c[i]) < m; ++i)
    ;
  cout << s[i];
  return 0;
}
