import sys

sys.stdin = open("prizes.in", "r")
sys.stdout = open("prizes.out", "w")

n = int(input())
a = list(map(int, input().split()))

ans = []
for i in range(1, n):
    b = a[:i + 1]
    b.sort()
    ans.append(b[-2])

print(" ".join(map(str, ans)))
    