N=int(input())
a=[0]*(N)
maxim=[0]*(N)
maxim1=0
maxim2=0
for i in range(N):
    a[i]=int(input())
    maxim[i]=a[i]
maxim=sorted(a, reverse=True)
maxim1=maxim[0]
for j in range(N):
    if maxim[0]!=maxim[j]:
        maxim2=maxim[j]
        break
for k in range(N):
    if a[k]!=maxim1:
        print(maxim1)
    elif a[k]==maxim1:
        print(maxim2)