n = int(input())
a = [0 for i in range(n)]
for i in range(n):
    a[i] = int(input())

a_max = [0 for i in range(n)]
a_max[0] = max(a[1:])
a_max[n-1] = max(a[:n])


for i in range(1,n-1):
    l_max = max(a[:i])
    r_max = max(a[i+1:])
    a_max[i] = max(l_max,r_max)

for i in a_max:
    print(i)