import copy
N=int(input())
A = [int(input()) for i in range(N)]
big=max(A)
flag=0
for i in range(N):
    if A[i]==big:
        if flag==0:
            flag==1
            hoge=copy.copy(A)
            hoge.pop(i)
            bigger=max(hoge)
            if bigger==big:
                print(big)
            else:
                print(bigger)
        else:
            print(bigger)
    else:
        print(big)