n = int(input())
a = [int(input()) for i in range(n)]
ff = [0] * n
fb = [0] * n
ff[0] = a[0]
for i in range(1, n):
    ff[i] = max(a[i], ff[i-1])
fb[n-1] = a[n-1]
for i in range(n-1)[::-1]:
    fb[i] = max(fb[i+1], a[i])
print(fb[1])
for i in range(1, n-1):
    print(max(ff[i-1], fb[n-i]))
print(ff[n-2])
