#include <iostream>
using namespace std;
const int MAX_SIZE = 10000;
const int MAX_VALUE = 500;
int main() {
int noElements, v[MAX_SIZE + 1], frq[MAX_VALUE + 1] = {0};
cin >> noElements;
for (int i = 1; i <= noElements; ++i) {
cin >> v[i];
++frq[v[i]];
}
int mostFrElement = 0, maxFrequency = 0;
for (int i = 0; i <= MAX_VALUE; ++i) {
if (frq[i] > maxFrequency) {
maxFrequency = frq[i];
mostFrElement = i;
} else if (frq[i] == maxFrequency) {
if (i > mostFrElement) {
mostFrElement = i;
}
}
}
cout << mostFrElement; // Afișăm elementul cu cea mai mare frecvență,sau care este cel mai mare de pe frecventa cea mai mare
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDA7CmNvbnN0IGludCBNQVhfVkFMVUUgPSA1MDA7CgppbnQgbWFpbigpIHsKICAgIGludCBub0VsZW1lbnRzLCB2W01BWF9TSVpFICsgMV0sIGZycVtNQVhfVkFMVUUgKyAxXSA9IHswfTsKICAgIGNpbiA+PiBub0VsZW1lbnRzOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbm9FbGVtZW50czsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV07CiAgICAgICAgKytmcnFbdltpXV07CiAgICB9CiAgICBpbnQgbW9zdEZyRWxlbWVudCA9IDAsIG1heEZyZXF1ZW5jeSA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBNQVhfVkFMVUU7ICsraSkgewogICAgICAgIGlmIChmcnFbaV0gPiBtYXhGcmVxdWVuY3kpIHsKICAgICAgICAgICAgbWF4RnJlcXVlbmN5ID0gZnJxW2ldOwogICAgICAgICAgICBtb3N0RnJFbGVtZW50ID0gaTsKICAgICAgICB9IGVsc2UgaWYgKGZycVtpXSA9PSBtYXhGcmVxdWVuY3kpIHsKICAgICAgICAgICAgaWYgKGkgPiBtb3N0RnJFbGVtZW50KSB7CiAgICAgICAgICAgICAgICBtb3N0RnJFbGVtZW50ID0gaTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgbW9zdEZyRWxlbWVudDsgLy8gQWZpyJnEg20gZWxlbWVudHVsIGN1IGNlYSBtYWkgbWFyZSBmcmVjdmVuyJvEgyxzYXUgY2FyZSBlc3RlIGNlbCBtYWkgbWFyZSBkZSBwZSBmcmVjdmVudGEgY2VhIG1haSBtYXJlCiAgICByZXR1cm4gMDsKfQ==