from collections import Counter N = int(input()) L = list(map(int,input().split())) d = Counter(L) max_v = 0 level = 0 for key in d: if d[key] >= max_v and key > level: max_v = d[key] level = key print(level)