n = int(input())
a = [int(input()) for i in range(n)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
for i in range(n):
    if i == a.index(a_first):
        print(a_second)
    else:
        print(a_first)