N = int(input())
max_1st = -1
max_1st_index = -1
max_2nd = -1
for i in range(0, N):
  if i == 0:
    max_1st = int(input())
    max_1st_index = 0
  elif i == 1:
    tmp = int(input())
    if (tmp > max_1st):
      max_1st, max_2nd = tmp, max_1st
      max_1st_index = 1
    else:
      max_2nd = tmp
  else:
    tmp = int(input())
    if (max_2nd < tmp) and (tmp < max_1st):
      max_2nd = tmp
    elif (max_1st < tmp):
      max_1st, max_1st_index = tmp, i

for j in range(0, N):
  if j == max_1st_index:
    print(max_2nd)
  else:
    print(max_1st)