N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
a_max = max(a[1:])
print(a_max)
for i in range(1,N-1):
    if(a[i]==a_max):
        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)
    else:
        if(a[i-1]>a_max):
            print(a[i-1])
        else:
            print(a_max)
print(max(a[:N-1]))
    