import numpy as np
n = int(input())

a = np.zeros((n))
for i in range(n):
    a_tmp = int(input())
    a[i] = a_tmp

f_min = np.zeros((n))
b_min = np.zeros((n))
for i in range(n):
    if i == 0:
        f_min[0] = a[0]
        b_min[n-1] = a[n-1]
    else:
        f_min[i] = max(f_min[i-1],a[i])
        b_min[n-1-i] = max(b_min[n-1-i+1],a[i])

#print(f_min)
#print(b_min)

for i in range(n):
    if i == 0:
        print(int(b_min[1]))
    elif i == (n-1):
        print(int(f_min[n-2]))
    else:
        print(int(max(b_min[i+1],f_min[i-1])))
