N = int(input())
A = []
for _ in range(N):
    A.append(input())

B = A.copy()
A_max = max(A)
B.remove(max(A))
second_max = max(B)
for i in A:
    if i == A_max:
        print(second_max)
    else:
        print(A_max)