input() l = list(map(int, input().split())) ans = (0, 0) for i in set(l): n = int(l.count(i)) if n > ans[0] or n == ans[0] and i > ans[1]: ans = (n, i) print(ans[1])