n = int(input())
a = [int(input()) for _ in range(n)]
res = [0] * n
for i in range(1, n):
	res[i] = max(res[i], a[i - 1])
for i in range(n - 2, -1, -1):
	res[i] = max(res[i], a[i + 1])
for i in range(n):
	print(res[i])