N = int(input().strip())

x = (int(input().strip()), 0)
y = (int(input().strip()), 1)
if x[0] > y[0]:
  x, y = y, x

for i in range(N - 2):
  a = int(input().strip())
  if a > x[0]:
    if a > y[0]:
      x = y
      y = (a, i)
    else:
      x = (a, i)

for i in range(N):
  if i == y[1]:
    print(x[0])
  else:
    print(y[0])