import numpy as np
import math
n=int(input())
a=[]
ans=[]
for i in range(n):
  a.append([i,int(input())])
b=sorted(a, key=lambda x: x[1])
if b[n-1][1]==b[n-2][1]:
  for i in range(n):
    print(b[n-1][1])
else:
  ans=np.full(n,b[n-1][1])
  ans[b[n-1][0]]=b[n-2][1]
  for i in range(n):
    print(ans[i])