#include <bits/stdc++.h>
using namespace std;
long long int i, j, k;
long long int sz = 1e6;
void solve() {
  long long int n;
  cin >> n;
  map<string, long long int> m, m2;
  string s[n], b = "";
  long long int a[n], max = -9999999999;
  for (long long int i = 0; i < n; i++) {
    cin >> s[i] >> a[i];
    m[s[i]] += a[i];
  }
  long long int ant = 0;
  for (long long int i = 0; i < n; i++) {
    if (max < m[s[i]]) {
      max = m[s[i]];
      b = s[i];
    }
  }
  for (long long int i = 0; i < n; i++)
    if (max == m[s[i]]) {
      ant++;
      b = s[i];
    }
  for (long long int i = 0; i < n; i++) {
    m2[s[i]] += a[i];
    if (m2[s[i]] >= max and m[s[i]] == max) {
      cout << s[i];
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n = 1;
  while (n--) {
    solve();
  }
  return 0;
}
