N=int(input())
x=[]
x+=list(int(input()) for i in range(N))
L==x
L.sort()
Max=L[N-1]
a=x.index(Max)
Maxsecond=L[N-2]
b=x.index(Maxsecond)
if Max==Maxsecond:
    for j in range(N):
        print(Max)
else:
    for k in range(N):
        if k==a:
            print(Maxsecond)
        else:
            print(Max)
