# coding: utf-8
n = int(input())

MAX = 0
MAX_index = []
MAX_sec = 0
for i in range(n):
    a = int(input())
    if MAX == a:
        MAX_index.append(i)
    elif MAX < a:
        MAX_index = [i]
        MAX = a
    elif MAX_sec < a:
        MAX_sec = a
    else:
        pass
    
#print(MAX_index)
        
if len(MAX_index)==1:
    for i in range(n):
        if i==MAX_index[0]:
            print(MAX_sec)
        else:
            print(MAX)
else:
    for i in range(n):
        print(MAX)
