#!/usr/bin/env python

A=[]
B = []
max = 0
max2 = 0
count = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
for i in range(len(A)):
    if A[i] > max:
        max = A[i]
        B.append(A[i])
for i in range(len(A)):
    if A[i] == max:
        count +=1

    
for i in range(len(A)):
    if count >= 2:
        print(max)
    if count == 1:
        if A[i] > max2 and A[i] != max:
            max2 = A[i]
for i in range(len(A)):
    if count ==1:
        if A[i] == max:
            print(max2)
        else:
            print(max)
