n = int(input())
apple = []
for _ in range(n):
    apple.append(int(input()))
big = max(apple[1:n+1])
print(big)
for i in range(1, n):
    if apple[i] != big:   
        if apple[i-1] >= big:
            print(apple[i-i])
            big = apple[i-1]
        else:
            print(big)
    else:
        orange = apple[0:i] + apple[i+1:n]
        print(max(orange))
        big = max(orange)