N = int(input())
A = [int(input()) for _ in range(N)]
#print(A)
max_index = set([i for i, x in enumerate(A) if x == max(A)])
l = len(max_index)
#print(max_index)
for i in range(N):
    if i in max_index and l-1==0:
        a = A[:i]+[0]
        b = A[i+1:]+[0]
        print(max(max(a),max(b)))
    else:
        print(max(A))