n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if num > max:
        max = num
    list.append(num)

for i,x in enumerate(list):
    if x == max:
        max_index.append(i)
    elif x > second:
        second = x

for i in range(n):
    if (i in max_index) & (len(max_index) == 1):
        print(second)
    else:
        print(max)
