#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
map<string, long long> m0, m1;
string s[MAXN];
long long c[MAXN], maximum = 0;
string ans;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
    m0[s[i]] += c[i];
  }
  for (int i = 0; i < n; i++) maximum = max(maximum, m0[s[i]]);
  for (int i = 0; i < n; i++) {
    m1[s[i]] += c[i];
    if (m0[s[i]] == maximum and m1[s[i]] >= maximum) {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
