#include <bits/stdc++.h>
using namespace std;
string name[1001];
int i, j, n, score[1001], m;
int main() {
  map<string, int> a, b;
  cin >> n;
  for (; i < n; i++) cin >> name[i] >> score[i], a[name[i]] += score[i];
  for (i = 0; i < n; i++) m = max(m, a[name[i]]);
  for (i = 0; a[name[i]] < m || (b[name[i]] += score[i]) < m; i++)
    ;
  cout << name[i] << "\n";
}
