N = int(input())
A_list = [int(input()) for i in range(N)]

big_1st = max(A_list[0], A_list[1])
big_2nd = min(A_list[0], A_list[1])

for i in range(2, N):
  if big_2nd < A_list[i] and A_list[i] < big_1st:
    big_2nd = A_list[i]
  elif big_1st < A_list[i]:
    big_2nd = big_1st
    big_1st = A_list[i]

for i in A_list:
  if i == big_1st:
    print(big_2nd)
  else:
    print(big_1st)