#include <bits/stdc++.h>
using namespace std;
int const MAX_N = 1000;
string _name[MAX_N];
int _score[MAX_N];
int n, score;
string name;
int main() {
  cin >> n;
  vector<string> p;
  vector<int> q;
  for (int i = 0; i < n; i++) {
    cin >> _name[i] >> _score[i];
    bool found = false;
    name = _name[i];
    score = _score[i];
    for (int j = 0; j < p.size(); j++) {
      if (p[j] == name) {
        q[j] += score;
        found = true;
        break;
      }
    }
    if (!found) {
      p.push_back(name);
      q.push_back(score);
    }
  }
  int m = -1, t = -1;
  for (int i = 0; i < q.size(); i++) {
    if (q[i] > m) {
      m = q[i];
      t = i;
    }
  }
  int c = 0;
  for (int i = 0; i < q.size(); i++) {
    if (q[i] == m) {
      c++;
    }
  }
  if (c == 1) {
    cout << p[t];
  } else {
    for (int i = 0; i < n; i++) {
      if (_score[i] >= m) {
        int temp = _score[i];
        for (int j = i + 1; j < n; j++) {
          if (_name[i] == _name[j]) {
            temp += _score[j];
          }
        }
        if (temp == m) {
          cout << _name[i];
          return 0;
        }
      }
      for (int j = i - 1; j >= 0; j--) {
        if (_name[i] == _name[j]) {
          _score[i] += _score[j];
          _score[j] = 0;
          if (_score[i] >= m) {
            int temp = _score[i];
            for (int k = i + 1; k < n; k++) {
              if (_name[i] == _name[k]) {
                temp += _score[k];
              }
            }
            if (temp == m) {
              cout << _name[i];
              return 0;
            }
          }
        }
      }
    }
  }
  return EXIT_SUCCESS;
}
