#include <iostream>
#include <cstring>
using namespace std;
const int TEN = 10;
const int MAX_SIZE = 10000;
int workerHours[MAX_SIZE + 1];
int main() {
int numberOfLines, maxHours = -1, workerWithMaxHours = -1;
cin >> numberOfLines;
cin.ignore();
for (int i = 0; i < numberOfLines; ++i) {
char line[MAX_SIZE];
cin.getline(line, MAX_SIZE);
int workerId = 0, hours = 0, numbersFound = 0;
for (int j = 0; line[j] != '\0'; ++j) {
if (line[j] >= '0' && line[j] <= '9') {
int number = 0;
while (line[j] >= '0' && line[j] <= '9') {
number = number * TEN + (line[j] - '0');
++j;
}
if (numbersFound == 0) {
workerId = number;
++numbersFound;
} else if (numbersFound == 1) {
hours = number;
++numbersFound;
}
}
}
workerHours[workerId] += hours;
if (workerHours[workerId] > maxHours) {
maxHours = workerHours[workerId];
workerWithMaxHours = workerId;
} else if (workerHours[workerId] == maxHours && workerId < workerWithMaxHours) {
workerWithMaxHours = workerId;
}
}
cout << workerWithMaxHours;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBURU4gPSAxMDsKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDA7CmludCB3b3JrZXJIb3Vyc1tNQVhfU0laRSArIDFdOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbnVtYmVyT2ZMaW5lcywgbWF4SG91cnMgPSAtMSwgd29ya2VyV2l0aE1heEhvdXJzID0gLTE7CiAgICBjaW4gPj4gbnVtYmVyT2ZMaW5lczsKICAgIGNpbi5pZ25vcmUoKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbnVtYmVyT2ZMaW5lczsgKytpKSB7CiAgICAgICAgY2hhciBsaW5lW01BWF9TSVpFXTsKICAgICAgICBjaW4uZ2V0bGluZShsaW5lLCBNQVhfU0laRSk7CiAgICAgICAgaW50IHdvcmtlcklkID0gMCwgaG91cnMgPSAwLCBudW1iZXJzRm91bmQgPSAwOwogICAgICAgIGZvciAoaW50IGogPSAwOyBsaW5lW2pdICE9ICdcMCc7ICsraikgewogICAgICAgICAgICBpZiAobGluZVtqXSA+PSAnMCcgJiYgbGluZVtqXSA8PSAnOScpIHsKICAgICAgICAgICAgICAgIGludCBudW1iZXIgPSAwOwogICAgICAgICAgICAgICAgd2hpbGUgKGxpbmVbal0gPj0gJzAnICYmIGxpbmVbal0gPD0gJzknKSB7CiAgICAgICAgICAgICAgICAgICAgbnVtYmVyID0gbnVtYmVyICogVEVOICsgKGxpbmVbal0gLSAnMCcpOwogICAgICAgICAgICAgICAgICAgICsrajsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChudW1iZXJzRm91bmQgPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHdvcmtlcklkID0gbnVtYmVyOwogICAgICAgICAgICAgICAgICAgICsrbnVtYmVyc0ZvdW5kOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChudW1iZXJzRm91bmQgPT0gMSkgewogICAgICAgICAgICAgICAgICAgIGhvdXJzID0gbnVtYmVyOwogICAgICAgICAgICAgICAgICAgICsrbnVtYmVyc0ZvdW5kOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdvcmtlckhvdXJzW3dvcmtlcklkXSArPSBob3VyczsKICAgICAgICBpZiAod29ya2VySG91cnNbd29ya2VySWRdID4gbWF4SG91cnMpIHsKICAgICAgICAgICAgbWF4SG91cnMgPSB3b3JrZXJIb3Vyc1t3b3JrZXJJZF07CiAgICAgICAgICAgIHdvcmtlcldpdGhNYXhIb3VycyA9IHdvcmtlcklkOwogICAgICAgIH0gZWxzZSBpZiAod29ya2VySG91cnNbd29ya2VySWRdID09IG1heEhvdXJzICYmIHdvcmtlcklkIDwgd29ya2VyV2l0aE1heEhvdXJzKSB7CiAgICAgICAgICAgIHdvcmtlcldpdGhNYXhIb3VycyA9IHdvcmtlcklkOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgd29ya2VyV2l0aE1heEhvdXJzOwogICAgcmV0dXJuIDA7Cn0=
NQpNdW5jaXRvcnVsIDEgYSBtdW5jaXQgMTAgb3JlCk11bmNpdG9ydWwgMjMgYSBtdW5jaXQgNSBvcmUKTXVuY2l0b3J1bCAzIGEgbXVuY2l0IDMgb3JlCk11bmNpdG9ydWwgMjMgYSBtdW5jaXQgMTEgb3JlCk11bmNpdG9ydWwgMSBhIG11bmNpdCAyIG9yZQo=
5
Muncitorul 1 a muncit 10 ore
Muncitorul 23 a muncit 5 ore
Muncitorul 3 a muncit 3 ore
Muncitorul 23 a muncit 11 ore
Muncitorul 1 a muncit 2 ore