N = int(input())
A = [int(input()) for _ in range(N)]
a_copy = A
a_max = max(a_copy)
b_max = list(set(a_copy))
b_max.remove(a_max)
b_max = max(b_max)

for i in A:
    if i == a_max:
        print(b_max)
    else:
        print(a_max)