from collections import Counter N = int(input()) cnt = Counter(list(map(int, input().split()))) al = 0 ac = 0 for a, b in cnt.most_common(): if ac <= b and al <= a: ac = b al = a print(al)