n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]
print(m2)

for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)
