n=int(input())
a=[int(input()) for i in range(n)]
M=max(a)
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    print(max(max(a[:k]),max(a[k+1:])))
  else:
    print(M)

