#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
map<string, int> a;
map<string, int> check;
string t[MAXN];
int main() {
  int n;
  cin >> n;
  int k[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> k[i];
    a[t[i]] += k[i];
  }
  int large = 0;
  for (map<string, int>::iterator it = a.begin(); it != a.end(); it++)
    large = max(large, (*it).second);
  for (int i = 0; i < n; i++) {
    check[t[i]] += k[i];
    if (check[t[i]] >= large && a[t[i]] == large) {
      cout << t[i];
      return 0;
    }
  }
}
