import math
import sys
minint = -sys.maxint - 1
maxint = sys.maxint

n = int(raw_input())
a = []
m = [0]*2
mx, mx2, ind, ind2 = minint, minint, 0, 0
for i in range(n):
  v = int(raw_input())
  if v > mx:
    mx, ind = v, i
  elif v > mx2:
    mx2, ind2 = v, i
  a += [v]
for i in range(n):
  if i == ind:
    print(mx2)
  else:
    print(mx)