sequence = []

N = int(input())

curr_el = max_el = second_el = int(input())
sequence.append(curr_el)
for i in range(1, N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (curr_el > max_el):
        second_el = max_el
        max_el = curr_el
    elif (curr_el > second_el):
        second_el = curr_el

# print('sequence', sequence)

for curr_el in sequence:
    answer = second_el if (max_el != second_el and curr_el == max_el) else max_el
    print(answer)
