N = int(input())

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

max_v1 = max(A)
max_v2 = 0

for i in range(N):
    if A[i] != max_v1 and A[i] > max_v2:
        max_v2 = A[i]

if max_v2 == 0:
    max_v2 = max_v1

for i in range(N):
    if A[i] != max_v1:
        print(max_v1)
    else:
        print(max_v2)