N = int(input())
A = [int(input()) for i in range(N)]
ans_1 = max(A)
tmp = set(A)
if len(tmp) >= 2:
    tmp.discard(max(tmp))
ans_2 = max(tmp)

for i in range(N):
    if A[i] != ans_1:
        print(ans_1)
    else:
        print(ans_2)