#include <bits/stdc++.h>
using namespace std;
map<string, int> p;
map<string, int> np;
vector<string> strs;
vector<int> h;
int main() {
  int n = 0;
  cin >> n;
  int max = 0;
  for (int i = 0; i < n; ++i) {
    string str;
    int c;
    cin >> str >> c;
    strs.push_back(str);
    h.push_back(c);
    p[str] += c;
  }
  for (map<string, int>::iterator it = p.begin(); it != p.end(); ++it) {
    if (it->second > max) {
      max = it->second;
    }
  }
  for (int i = 0; i < n; ++i) {
    np[strs[i]] += h[i];
    if (max == p[strs[i]] && np[strs[i]] >= max) {
      cout << strs[i] << endl;
      return 0;
    }
  }
  return 0;
}
