#include <bits/stdc++.h>
using namespace std;
const long long B = 31;
const long long M = 1000000000 + 7;
vector<long long> pos;
long long compute(string s, long long m) {
  long long hashVal = 0, pow = 1;
  for (int i = m - 1; i >= 0; i--) {
    hashVal = (hashVal + (((s[i] - 'a' + 1) * pow) % M)) % M;
    pow = (pow * B) % M;
  }
  return hashVal;
}
long long match(string pat, string text) {
  long long m = pat.size(), n = text.size(), pow = 1;
  if (n < m || !n || !m) return -1;
  long long patHash = compute(pat, m);
  long long textHash = compute(text, m);
  if (patHash == textHash) {
    pos.push_back(0);
  }
  for (int i = 0; i < m - 1; i++) {
    pow = (pow * B) % M;
  }
  for (int i = m; i < n; i++) {
    textHash = (textHash - ((text[i - m] - 'a' + 1) * pow) % M) % M;
    textHash = (textHash + M) % M;
    textHash = (textHash * B) % M;
    textHash = (textHash + (text[i] - 'a' + 1)) % M;
    if (textHash == patHash) {
      pos.push_back(i - m + 1);
    }
  }
  if (pos.size())
    return 1;
  else
    return -1;
}
vector<pair<string, int> > points;
map<string, int> mp;
string s[12345];
int main() {
  int n, mx = INT_MIN;
  string name, winner;
  cin >> n;
  int t = n;
  while (t--) {
    long long x;
    cin >> name >> x;
    s[t] = name;
    mp[name] += x;
    points.push_back({name, mp[name]});
  }
  for (int i = 0; i < n; i++) {
    mx = max(mx, mp[s[i]]);
  }
  for (int i = 0; i < n; i++) {
    if (points[i].second >= mx && mp[points[i].first] == mx) {
      cout << points[i].first;
      return 0;
    }
  }
  return 0;
  long long m;
  bool okay = 0;
  string text, pat;
  while (cin >> m) {
    pos.clear();
    cin >> pat >> text;
    if (match(pat, text) != -1) {
      if (okay) {
        puts("");
      }
      for (int i = 0; i < pos.size(); i++) cout << pos[i] << endl;
    } else
      continue;
    okay = 1;
  }
  return 0;
}
