#include <bits/stdc++.h>
using namespace std;
const int MAX = 1010;
int n;
string s[MAX];
int cnt[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> cnt[i];
    mp[s[i]] += cnt[i];
  }
  int ma = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ma = max(ma, it->second);
  }
  map<string, int> mp2;
  for (int i = 0; i < n; i++) {
    mp2[s[i]] += cnt[i];
    if (mp[s[i]] == ma && mp2[s[i]] >= ma) {
      cout << s[i] << endl;
      break;
    }
  }
  return 0;
}
