#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 1e7 + 7;
const long long int MOD = 1000000007;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int main() {
  fast();
  long long int TEST_CASES = 1;
  while (TEST_CASES--) {
    int n;
    cin >> n;
    vector<pair<string, int>> v(n);
    map<string, long long int> mp, now;
    for (long long int(i) = 0; (i) < n; (i)++) {
      cin >> v[i].first >> v[i].second;
      mp[v[i].first] += v[i].second;
    }
    string mxs;
    long long int mx = INT_MIN;
    for (auto i : mp) {
      if (mx < i.second) {
        mx = i.second;
        mxs = i.first;
      }
    }
    string str;
    for (int i = 0; i < n; i++) {
      now[v[i].first] += v[i].second;
      if (mp[v[i].first] == mx && now[v[i].first] >= mx) {
        str = v[i].first;
        break;
      }
    }
    cout << str << "\n";
  }
  return 0;
}
