#include <bits/stdc++.h>
using namespace std;
long long int lar(long long int a, long long int b) {
  return ((a >= b) ? a : b);
}
long long int les(long long int a, long long int b) {
  return ((a <= b) ? a : b);
}
const int MAX = 1e6 + 9;
int main() {
  long long int n, m, mx = 0, i;
  string st, g;
  vector<pair<string, long long int>> v;
  map<string, long long int> mp;
  map<string, long long int>::iterator j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> st >> m;
    if (mp.find(st) == mp.end())
      mp[st] = m;
    else
      mp[st] += m;
    v.push_back({st, mp[st]});
  }
  for (j = mp.begin(); j != mp.end(); ++j) {
    mx = lar(mx, j->second);
  }
  for (i = 0; i < v.size(); i++) {
    if (mp[v[i].first] == mx && v[i].second >= mx) {
      g = v[i].first;
      break;
    }
  }
  cout << g << endl;
  return 0;
}
