import itertools
import math
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

maxR = [0] * n
maxL = [0] * n
maximum = 0
for i in range(n):
    maximum = max(maximum,a[i])
    maxL[i] = maximum
maximum = 0
for i in range(n):
    maximum = max(maximum,a[n-i-1])
    maxR[n-i-1] = maximum


print(maxR[0])
for i in range(1,n-1):
    print(max(maxL[i-1],maxR[i+1]))
print(maxL[n-1])