#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
map<string,long long>a;
set<string>ak;
long long n;
int main()
{
cin >> n;
string name,kkk;
long long score,res = -(1e9);
for(int i = 1 ; i <= n ; i ++ )
{
cin >> name >> score;
ak.insert(name);
a[name] += score;
if(a[name] > res)
res = a[name],
kkk = name;
}
for (auto i:ak){
if(a[i] > res)
res = a[i],
kkk = i;
}
cout << kkk << endl;
return 0;
}