import numpy as np
N = int(input())
A = list(int(input()) for i in range(N))
for i in range(N):
    p= A[i]

    M = max(A)
    del A[i]
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.insert(i,p)