N=int(input())
list=[]
for i in range(N):
  A=int(input())
  list.append(A)
l=sorted(list,reverse=True)
k=set(list)
A_1=k[0]
A_2=k[1]
for j in range(N):
  if list[j]!=A_1:
    print(A_1)
  else:
    print(list[1])
