N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
c = []
mL = 0
mR = 0
m = 0
for i,a in enumerate(A):
    if i == 0:
        mR = max(A[i + 1 :])
        print(mR)
    elif i == len(A) - 1:
        mL = max(A[0: i])
        print(mL)
    else:
        mL = max(A[0: i])
        mR = max(A[i + 1 :])
        m = max(mL, mR)
        print(m)
    