n = int(input())
A = [int(input()) for _ in range(n)]

first = 0
second = 0
for i in range(1, n):
    if A[first] < A[i]:
        second = first
        first = i
    elif A[second] < A[i]:
        second = i

print(*[A[first] if i != first else A[second] for i in range(n)], sep='\n')
