N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))

first_max = 0
latter_max = max(a[1:])

for i in range(0, N - 1):
  if i > 0:
    first_max = max(first_max, a[i-1])
  if latter_max == a[i]:
    latter_max = max(a[i+1:])
  print(max(first_max, latter_max))

print(max(a[:-1]))