#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    res = ((res % mod) * ((n - i) % mod)) % mod;
    res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long max(long long a, long long b) {
  long long sol = a > b ? a : b;
  return sol;
}
long long min(long long a, long long b) {
  long long sol = a < b ? a : b;
  return sol;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  vector<pair<string, long long>> v;
  map<string, long long> mp;
  map<string, long long> m;
  long long r = 0;
  cin >> n;
  while (n--) {
    string s;
    long long d;
    cin >> s >> d;
    v.push_back({s, d});
    mp[s] += d;
  }
  string ans;
  for (auto it : mp) {
    r = max(r, it.second);
  }
  for (auto it : v) {
    m[it.first] += it.second;
    if (m[it.first] >= r and mp[it.first] == r) {
      ans = it.first;
      break;
    }
  }
  cout << ans;
}
