N=int(input())
a=[int(input()) for i in range(N)]
sw=True
b=sorted(a,reverse=True)

for j in range(N-1):
    if b[j]>b[j+1]:
        max2=b[j+1]
        max1=b[j]
        sw=False
        break

if sw==True:
    max1=b[0]
    for k in range(N):
        print(max1)
else:
    for k in range(N):
        if a[k]==max1:
            print(max2)
        else:
            print(max1)
