#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int mod = 1e9 + 7;
int dcmp(long double x, long double y) {
  return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n;
map<string, int> score;
map<int, vector<pair<string, int> > > ft;
int main() {
  fast();
  cin >> n;
  string s;
  int x, mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> s >> x;
    score[s] += x;
    ft[score[s]].push_back({s, i});
  }
  for (auto e : score) {
    mx = max(mx, e.second);
  }
  int mn = 2e9;
  string wn = "";
  for (auto &e : ft) {
    if (e.first < mx) continue;
    for (int i = 0; i < e.second.size(); i++) {
      if (score[e.second[i].first] == mx) {
        if (mn > e.second[i].second) {
          mn = e.second[i].second;
          wn = e.second[i].first;
        }
      }
    }
  }
  cout << wn << '\n';
  return 0;
}
