n = input() l = list(map(int, input().split())) x = [_ for _ in set(l) if l.count(_)>1] print(max(x if x else l))