N = int(input())
number = []
for i in range(N):
    number.append(int(input()))
    
if N == 2:
    print(number[0])
    print(number[1])
    exit()
    
if N == 3:
    print(max(number[1:]))
    print(max(number[2:]))
    print(max(number[:2]))    
    exit()
    
print(max(number[1:]))
for i in range(1,N-1):
    max_low = max(number[:i])
    max_upp = max(number[i+1:])
    print(max(max_low,max_upp))
print(max(number[:-1]))