#include <bits/stdc++.h>

using namespace std;
int n, maxx=1;
int a[1000005], b[1000005];
int minn=1e9;
int main(){
        ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    freopen("BAI1.INP","r", stdin);
    freopen("BAI1.OUT","w", stdout);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[a[i]]++;
        maxx=max(maxx,b[a[i]]);
    }
    for(int i=1;i<=n;i++){
        if(b[a[i]]==maxx && a[i]<minn) minn=a[i];
    }
    cout<<minn;
    return 0;
}
