#include <bits/stdc++.h>
using namespace std;
const int N = int(1e3);
const int inf = int(1e9);
pair<string, int> a[N];
map<string, int> x, y;
int main() {
  int n, m = -inf;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    x[a[i].first] += a[i].second;
  }
  for (map<string, int>::iterator it = x.begin(); it != x.end(); it++)
    m = max(m, it->second);
  for (int i = 0; i < n; i++) {
    y[a[i].first] += a[i].second;
    if (x[a[i].first] == m && m <= y[a[i].first]) {
      cout << a[i].first;
      return 0;
    }
  }
  return 0;
}
