N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
B = [i for i in A if i != max(A)]
ma = max(A)
if len(B)==0:
    mb = max(A)
else:
    mb = max(B)
for i in range(N):
    if A[i]==ma:
        print(mb)
    else:
        print(ma)