N = int(input())
A = []
maximum = []
for i in range(N):
    a = 0
    a = int(input())
    A.append(a)
    if i == 0:
        maximum = [0, a]
    elif maximum[1] < a:
        maximum = [i, a]
A = tuple(A)
B = list(A)

for j in range(N):
    if j == maximum[0]:
        del B[j]
        print(max(B))
    else:
        print(max(A))