#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const int N = 1e6 + 100;
const long long int mod = 1e9 + 9;
const long long int hash = 311;
const long long int INF = 1e18;
pair<string, int> a[1100];
map<string, bool> mark;
map<string, int> m;
map<string, int> mm;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    m[a[i].first] += a[i].second;
  }
  int mx = 0;
  vector<string> v;
  for (auto i : m) {
    if (i.second > mx) {
      v.clear();
      mx = i.second;
    }
    if (i.second == mx) v.push_back(i.first);
  }
  for (auto i : v) mark[i] = true;
  for (int i = 0; i < n; i++) {
    mm[a[i].first] += a[i].second;
    if (mm[a[i].first] >= mx && mark[a[i].first]) {
      cout << a[i].first;
      return 0;
    }
  }
}
