import numpy as np
n = int(input())
lst=[]
for i in range(n):
  a=int(input())
  lst.append(a)
nplst=np.array(lst)
m=max(lst)
ans=np.ones(n)*m
if len(nplst[nplst==m])==1:
  q=lst.index(m)
  ans[q]=max(max(nplst[:q]),max(nplst[q+1:]))
for i in range(n):
  print(int(ans[i]))