#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;
int 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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDA7CmNvbnN0IGludCBNQVhfVkFMVUUgPSA1MDA7CgppbnQgbWFpbigpIHsKICAgIGludCBub0VsZW1lbnRzLCB2W01BWF9TSVpFICsgMV0sIGZycVtNQVhfVkFMVUUgKyAxXSA9IHsKICAgICAgICAwCiAgICB9OwogICAgY2luID4+IG5vRWxlbWVudHM7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBub0VsZW1lbnRzOyArK2kpIHsKICAgICAgICBjaW4gPj4gdltpXTsKICAgICAgICArK2ZycVt2W2ldXTsKICAgIH0KICAgIGludCBtb3N0RnJFbGVtZW50ID0gMDsKICAgIGludCBtYXhGcmVxdWVuY3kgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gTUFYX1ZBTFVFOyArK2kpIHsKICAgICAgICBpZiAoZnJxW2ldID4gbWF4RnJlcXVlbmN5KSB7CiAgICAgICAgICAgIG1heEZyZXF1ZW5jeSA9IGZycVtpXTsKICAgICAgICAgICAgbW9zdEZyRWxlbWVudCA9IGk7CiAgICAgICAgfSBlbHNlIGlmIChmcnFbaV0gPT0gbWF4RnJlcXVlbmN5KSB7CiAgICAgICAgICAgIGlmIChpID4gbW9zdEZyRWxlbWVudCkgewogICAgICAgICAgICAgICAgbW9zdEZyRWxlbWVudCA9IGk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IG1vc3RGckVsZW1lbnQ7IC8vIEFmaciZxINtIGVsZW1lbnR1bCBjdSBjZWEgbWFpIG1hcmUgZnJlY3ZlbsibxIMsc2F1IGNhcmUgZXN0ZSBjZWwgbWFpIG1hcmUgZGUgcGUgZnJlY3ZlbnRhIGNlYSBtYWkgbWFyZQogICAgcmV0dXJuIDA7Cn0=