N = int(input())
A =[int(input()) for _ in range(N)]

B = sorted(set(A[:]))
firstMax = B[-1]
secondMax = firstMax

if len(B)>1:
    secondMax = B[-2]

for i in A:
    if i == firstMax:
        print(secondMax)
    else:
        print(max(i, firstMax))