import numpy as np
N=int(input())
A=[int(input()) for i in range(N)]
Amax=max(A)

Ai=np.argmax(A)
if Ai==0:
  A2max=max(A[Ai+1:])
elif Ai==N-1:
  A2max=max(A[:Ai])
else:
  A2max=max(A[:Ai],A[Ai+1:])[0]

for i in range(N):
  if i==Ai:
    print(A2max)
  else:
    print(Amax)