import numpy as np
N = int(input())

a = []
for i in range(N):
    a.append(int(input()))

all_max = max(a)
max_arg = np.argmax(a)

print(max(a[1:]))

for i in range(1,N-1):
    if i!=max_arg:
        print(all_max)
    else:
        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]))
    