from collections import Counter as c n=input() d=c(map(int,input().split())) print(sorted(d.items(),key=lambda x:(-x[1],-x[0]))[0][0])