N = int(input())
A = [int(input()) for i in range(N)]


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_second_max = list(A_hash.keys())
A_second_max.sort()

if len(A_second_max) > 1:
        A_second_max = A_second_max[1]
else:
        A_second_max = A_second_max[0]

for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)
