import copy

N=int(input())
A=[input() for i in range(N)]
copy_A=copy.copy(A)

all_max=max(A)  #O(N)
all_max_index=A.index(all_max)

copy_A.remove(all_max)
next_max=max(copy_A)

for i in range(N):
    if i!=all_max_index:
        print(all_max)
    else:
        print(next_max)
        






