#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
map<string, int> mp, mp2;
int n, mx = -1e9, in2[1010];
string ans, in[1010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> in[i] >> in2[i];
    mp[in[i]] += in2[i];
  }
  for (int i = 0; i < n; i++) mx = max(mx, mp[in[i]]);
  for (int i = 0; i < n; i++) {
    mp2[in[i]] += in2[i];
    if (mp2[in[i]] >= mx && mp[in[i]] == mx) {
      cout << in[i] << endl;
      return 0;
    }
  }
  return 0;
}
