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:
    if k==0:
      print(max(a[1:]))
    if k==n-1:
      print(max(a[:n-1]))
    else:
      print(max(a[:k]+a[k+1:]))
  else:
    print(M)

