N = int(input())
A = [int(input()) for _ in range(N)]
 
# M_list = index(max(A_1,...,A_N))
# M = max(A)
# sub_M = sub_max(A)

# iがM_listに含まれるときにはsub_Mを出力
# それ以外ではMを出力

M = max(A)
sub_M = 0
for i in range(N):
  if i not in M_list:
    sub_M = max(sub_M, A[i])
    
M_list = []
for i in range(N):
  if A[i] == M: M_list.append(i)
    
for i in range(N):
  if i in M_list: print(sub_M)
  else: print(M)