N = int(input())
data = []
max1 = 0
max2 = 0
for i in range(N):
    x = int(input())
    if x >= max1:
        max1 = x
        max_i = i
    elif x >= max2:
        max2 = x
for i in range(N):
    if max_i == i:
        print(max2)
    else:
        print(max1)