N = int(input())
num_dict = {}

num_list = [int(input()) for i in range(N)]
max_num = max(num_list)

for cnt in range(N):
  if num_list[cnt] == max_num:
    print(max(num_list[0:cnt] + num_list[cnt+1:]))
  else:
    print(max_num)