import sys
N = int(input())

A = []
for i in range(N):
  tmp = int(input())
  A.append(tmp)

A_set = set(A)
if len(A_set)==1:
  val = A[0]
  for i in range(N):
    print(val)
  sys.exit()

else:
  second_max = sorted(A_set)[-2]

tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]

tmp_list = [tmp_max] * N
#[式 for 任意の変数名 in イテラブルオブジェクト if 条件式]
#l_odd = [i for i in l if not i % 2 == 0]
for i in len(tmp_max_list):
  tmp_list[tmp_max_list[i]]=second_max

for i in range(N):
  print(tmp_list[i])
