n = int(input())
A = []
maximum = 0
maximum_idx = 0
for i in range(n):
    a = int(input())
    A.append(a)
    if a > maximum:
        maximum = a
        maximum_idx = i

for i in range(n):
    if i != maximum_idx:
        print(maximum)
    else:
        print(sorted(A)[1])
