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

A_max = max(A_set)
A_set.remove(A_max)
if len(A_set) == 0:
    for i in A:
        print(A_max)
else:
    A_next = max(A_set)
    for i in A:
        if i == A_max:
            print(A_next)
        else:
            print(A_max)