n = int(input())
a = [int(input()) for i in range(n)]
ahead = 0
back = max(a[1:])
result = [back]
for i in range(1,n-1):
    ahead = max(ahead,a[i-1])
    if back == a[i]:
        back = max(a[(i+1):])
    result.append(max(ahead,back))
ahead = max(ahead,a[n-2])
result.append(ahead)
for j in range(n):
    print(result[j])