#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, t, n[1001], m = 0;
  string s[1001];
  map<string, int> f, g;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> s[i] >> n[i];
    f[s[i]] += n[i];
  }
  for (i = 0; i < t; i++) {
    m = max(m, f[s[i]]);
  }
  i = 0;
  while (f[s[i]] < m || (g[s[i]] += n[i]) < m) i++;
  cout << s[i] << endl;
  return 0;
}
