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