N = int(input())
A = ([int(input()) for n in range(N)])
sorted_A = sorted(A)
max_ = A[len(A)-1]
semi_max = A[len(A)-2]


for i in range(N):
    if(A[i]==max_):
        print(semi_max)
    else:
        print(max_)