#include <bits/stdc++.h>
using namespace std;
map<string, int> name, name2;
const int maxn = 1e3 + 10;
string s[maxn];
int A[maxn];
int main() {
  int n;
  cin >> n;
  int maxx = -999999999;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> A[i];
    name[s[i]] += A[i];
  }
  for (int i = 0; i < n; i++) maxx = max(maxx, name[s[i]]);
  for (int i = 0; i < n; i++) {
    name2[s[i]] += A[i];
    if (name2[s[i]] >= maxx && name[s[i]] == maxx) {
      cout << s[i];
      return 0;
    }
  }
  return 0;
}
