#include <bits/stdc++.h>
using namespace std;
bool check(vector<string> &arr, string &s) {
  bool flag = false;
  for (int i = 0; i < arr.size(); ++i) {
    if (arr[i] == s) flag = true;
  }
  return flag;
}
int main() {
  int n;
  cin >> n;
  map<string, int> pos;
  vector<pair<string, int>> arr;
  for (int i = 0; i < n; ++i) {
    string s;
    int el;
    cin >> s >> el;
    pos[s] += el;
    arr.push_back({s, el});
  }
  int mx = -1e5;
  vector<string> win;
  for (auto [key, val] : pos) {
    if (val > mx) {
      mx = val;
      while (win.size() > 0) {
        win.pop_back();
      }
      win.push_back(key);
    } else if (val == mx) {
      win.push_back(key);
    }
  }
  map<string, int> nmp;
  for (int i = 0; i < n; ++i) {
    nmp[arr[i].first] += arr[i].second;
    if (check(win, arr[i].first) && nmp[arr[i].first] >= mx) {
      cout << arr[i].first << endl;
      break;
    }
  }
  return 0;
}
