#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
string s, s1;
int arr[100009], str2[1002], arr2[100009];
string str[1002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll m = 1e5 + 9;
  int i, t, x, j = 0;
  ll pow[33];
  pow[0] = 1;
  for (i = 1; i < 33; i++) {
    pow[i] = (pow[i - 1] * 31) % m;
  }
  cin >> t;
  memset(arr, 0, sizeof(arr));
  memset(arr2, 0, sizeof(arr2));
  while (t--) {
    cin >> s >> x;
    str[j] = s;
    str2[j] = x;
    j++;
    ll h;
    h = 0;
    for (i = 0; i < s.length(); i++) {
      h = (h + (s[i] * pow[i]) % m) % m;
    }
    arr[h] += x;
    arr2[h] += x;
  }
  t = j;
  sort(arr, arr + 100009);
  int m1 = arr[100008];
  memset(arr, 0, sizeof(arr));
  for (j = 0; j < t; j++) {
    ll h;
    h = 0;
    for (i = 0; i < str[j].length(); i++) {
      h = (h + (str[j][i] * pow[i]) % m) % m;
    }
    arr[h] += str2[j];
    if (arr[h] >= m1 && arr2[h] == m1) {
      s1 = str[j];
      break;
    }
  }
  cout << s1;
}
