N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
print(max(a[1:]))
for i in range(1,N-1):
    a_max = max(a[:i])
    n_a_max = max(a[i+1:])
    if(a_max>=n_a_max):
        print(a_max)
    else:
        print(n_a_max)
print(max(a[:N-1]))
    