#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
map<string, int> M;
map<string, int> MM;
vector<string> V;
vector<int> VV;
int main() {
  int n;
  while (cin >> n) {
    M.clear();
    MM.clear();
    V.clear();
    VV.clear();
    string x;
    int y;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      M[x] += y;
      V.push_back(x);
      VV.push_back(y);
    }
    int mx = -1;
    for (int i = 0; i < n; i++) {
      mx = max(mx, M[V[i]]);
    }
    for (int i = 0; i < n; i++) {
      MM[V[i]] += VV[i];
      if (MM[V[i]] >= mx and (M[V[i]] == mx)) {
        cout << V[i] << endl;
        break;
      }
    }
  }
  return 0;
}
