N = int(input())
A = [int(input()) for _ in range(N)]
mx1 = max(A)
mx2 = -1
for i in range(N):
    if A[i] != mx1:
        mx2 = max(mx2, A[i])
if mx2 == -1:
    mx2 = mx1
for i in range(N):
    if A[i] == mx1:
        print(mx2)
    else:
        print(mx1)