#include <bits/stdc++.h>
using namespace std;
long long n, a[2000], mas[2000], maxx, maxx1, ans, ind;
pair<string, long long> p[2000];
map<string, long long> m, m1;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
  for (int i = 1; i <= n; i++) m[p[i].first] += p[i].second;
  for (int i = 1; i <= n; i++) maxx = max(maxx, m[p[i].first]);
  for (int i = 1; i <= n; i++) {
    m1[p[i].first] += p[i].second;
    if (maxx == m[p[i].first] && m1[p[i].first] >= maxx) {
      cout << p[i].first;
      return 0;
    }
  }
}
