#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    string ans1 = "-1";
    int ans2 = INT_MIN;
    unordered_map<string, int> mp;
    vector<pair<string, int>> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec[i].first;
      cin >> vec[i].second;
      mp[vec[i].first] += vec[i].second;
      vec[i].second = mp[vec[i].first];
    }
    int maxi = INT_MIN;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      maxi = max(maxi, it->second);
    }
    for (int i = 0; i < n; i++) {
      if (mp[vec[i].first] == maxi && vec[i].second >= maxi) {
        ans1 = vec[i].first;
        break;
      }
    }
    cout << ans1 << "\n";
  }
  return 0;
}
