import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) L=[int(i) for i in input().split()] import collections LL=collections.Counter(L) k,v=0,0 for l in LL.keys(): if LL[l]>v: k=l v=LL[l] elif LL[l]==v: if l>k: k=l print(k)