input() l={} for i in map(int,input().split()): if i in l: l[i] += 1 else: l[i] = 1 print(l) ans,amt = 0,0 for i in l: if l[i] > amt: ans,amt = i,l[i] elif l[i] == amt and i > ans: ans,amt = i,l[i] print(ans)