import numpy as np
n = int(input())
nplst=np.array([int(input()) for i in range(n)])
m=max(nplst)
ans=np.ones(n,dtype="int32")*m
if len(np.where(nplst==m))==1:
  q=int(np.where(nplst==m)[0])
  ans[q]=max(max(nplst[:q]),max(nplst[q+1:]))
a_int = ans.astype(np.str)
print("\n".join(a_int))