N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
m = max(A)
for i in range(N):
        if A[i] == m:
                A.remove(m)
                print(max(A))
                A.insert(i,m)
        else:
                print(m)