import numpy as np
N = int(input())
A = np.array([int(input()) for _ in range(N)])
B = np.copy(A)
B = np.sort(B)[::-1]
a = A[np.where(B[0])]
for i in range(N):
    if i == a:
        print(B[1])
    else:
        print(B[0])