import sys

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

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

max1 = 0
max2 = 0
ans = []
for i in range(n):
    if a[i] > max1:
        max1, max2 = a[i], max1
    elif a[i] > max2:
        max2 = a[i]
    if i > 0:
        ans.append(max2)

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