import copy
n=int(input())
a=[int(input()) for i in range(n)]
a_copy=copy.deepcopy(a)
max_num=max(a)
sec_num=0
answer=[]
a_copy=sorted(a_copy)
for i in range(len(a_copy)):
  if max_num>a_copy[-(i+1)]:
    sec_num=a_copy[-(i+1)]
    break
for j in range(len(a)):
  if a[j]==max_num and sec_num!=0:
    answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print(answer[k])