#include <bits/stdc++.h>
using namespace std;
pair<string, int> a[1234];
map<string, int> mp, mp1;
int main() {
  int ans = -1e9;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    int q;
    cin >> s >> q;
    a[i] = {s, q};
    mp[s] += q;
  }
  for (auto it : mp) {
    ans = max(ans, it.second);
  }
  for (int i = 1; i <= n; i++) {
    mp1[a[i].first] += a[i].second;
    if (mp1[a[i].first] >= ans && mp[a[i].first] == ans) {
      cout << a[i].first;
      return 0;
    }
  }
  getchar();
  getchar();
  return 0;
}
