N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
if B.count(max(B))==1:
    B.remove(max(B))
    b=max(B)
else:
    b=max(B)
c=max(A)
for j in range(N):
    if A[j]==max(A):
        print(b)
    else:
        print(c)
