n = int(input())
A = [int(input()) for i in range(n)]
m = str(max(A))
ANS = []

for i in range(n):
    if i == A.index(max(A)):
        ans = A[:]
        ans.pop(i)
        ANS.append(str(max(ans)))
    else:
        ANS.append(m)

print('\n'.join(ANS))