from collections import Counter _ = int(input()) print(sorted(Counter(map(int, input().split())).most_common(), key=lambda x: (-x[1], -x[0]))[0][0])