#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(false);
unsigned long long n; // n <= 1e6
long long m = 1000;
long long o = 1000000;
long long largest_pos[o];
long long largest_nextpos = 1;
cin >> n;
unsigned long long a[m]; // a <= 1000
for (long long i = 1; i <= n; i++){
cin >> m;
a[m]++;
if (a[m] > a[largest_pos[largest_nextpos]]){
largest_pos[1]=m;
largest_nextpos=1;
}
else if (a[m] = a[largest_pos[largest_nextpos]]){
largest_nextpos++;
}
else continue;
}
//for (long long j = 1; j <= n;)
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzaWduZWQgbWFpbigpewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoKICAgIHVuc2lnbmVkIGxvbmcgbG9uZyBuOyAvLyBuIDw9IDFlNgogICAgbG9uZyBsb25nIG0gPSAxMDAwOwogICAgbG9uZyBsb25nIG8gPSAxMDAwMDAwOwogICAgbG9uZyBsb25nIGxhcmdlc3RfcG9zW29dOwogICAgbG9uZyBsb25nIGxhcmdlc3RfbmV4dHBvcyA9IDE7CiAgICBjaW4gPj4gbjsKICAgIHVuc2lnbmVkIGxvbmcgbG9uZyBhW21dOyAvLyBhIDw9IDEwMDAKICAgIGZvciAobG9uZyBsb25nIGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgY2luID4+IG07CiAgICAgICAgYVttXSsrOwogICAgICAgIGlmIChhW21dID4gYVtsYXJnZXN0X3Bvc1tsYXJnZXN0X25leHRwb3NdXSl7CiAgICAgICAgICAgIGxhcmdlc3RfcG9zWzFdPW07CiAgICAgICAgICAgIGxhcmdlc3RfbmV4dHBvcz0xOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChhW21dID0gYVtsYXJnZXN0X3Bvc1tsYXJnZXN0X25leHRwb3NdXSl7CiAgICAgICAgICAgIGxhcmdlc3RfbmV4dHBvcysrOwogICAgICAgIH0KICAgICAgICBlbHNlIGNvbnRpbnVlOwogICAgfQogICAgLy9mb3IgKGxvbmcgbG9uZyBqID0gMTsgaiA8PSBuOykKfQ==