N = int(input()) V = list(map(int,input().split())) list = [0, 0] for i in V: list.sort() if i > list[0] or i > list[1]: list[0] = i else: continue print(sum(list))