n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)

if len(top_idx) > 1:
  semi_top = top_val

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))