N = int(input())

A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    A.append(ai)


A2 = sorted(A)

max1 = A2[len(A2)-1]
max2 = A2[len(A2)-2]

for i in range(N):
    if max1 == A2[i]:
        print(max2)
    else:
        print(max1)