#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int n;
  cin >> n;
  map<string, long long> sum, sum2;
  long long maxi = 0;
  string s[n];
  long long score[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> score[i];
    sum[s[i]] += score[i];
  }
  for (auto i : sum) {
    maxi = max(maxi, i.second);
  }
  for (int i = 0; i < n; i++) {
    sum2[s[i]] += score[i];
    if (sum2[s[i]] >= maxi && sum[s[i]] == maxi) return cout << s[i], 0;
  }
  return 0;
}
