n=int(input())
A=[]
for i in range(n):
    a=int(input())
    A.append(a)
M=max(A)
for i in range(n):
    if A[i]!=M:
        print(M)
    else:
        b=A.pop(i)
        print(max(A))
        A.insert(i,b)