N = int(input())
A = [0]*N
for i in range (N):
    A[i] = int(input()) 

max1 = 0
max2 = 0
for i in range (N):
    if A[i] >= max1:
        max1 = A[i]
    elif A[i] >= max2:
        max2 = A[i]

for i in range (N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)