n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
for i in range(n):
    a = int(input())
    if a > max_1:
        max_1 = a
        count = 1
        max1_index = [i]
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 > a and a > max_2:
        max_2 = a
        max2_index = i
    an.append(a)
    
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)