import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
print(max(a[1:]))
for i in range(1,n-1):
    print(max(max(a[:i]),max(a[i+1:])))
    
print(max(a[:n-1]))