#include <bits/stdc++.h>
char a[1002][34], b[34];
int point[1002], res[1002], h[1002];
int main() {
  int n, x, i, j, p = 1;
  scanf("%d", &n);
  scanf("%s %d", &a[0], &x);
  point[0] += x;
  h[0] = point[0];
  res[0] = 0;
  for (i = 1; i < n; i++) {
    scanf("%s %d", &b, &x);
    for (j = 0; j < p; j++) {
      if (strcmp(a[j], b) == 0) {
        break;
      }
    }
    if (i == p) {
      strcpy(a[p], b);
      p++;
    }
    point[j] += x;
    h[i] = point[j];
    res[i] = j;
  }
  int max = point[0];
  for (i = 1; i < p; i++) {
    if (point[i] > max) max = point[i];
  }
  for (i = 0; i < n; i++) {
    if (point[res[i]] == max && h[i] >= max) break;
  }
  printf("%s", a[res[i]]);
}
