sequence = []

N = int(input())

count = 0

for i in range(N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (i == 0):
        max_el = second = curr_el
    elif (curr_el >= max_el):
        max_el = curr_el
    elif (curr_el >= second):
        second = curr_el

# print('sequence', sequence)

for curr_el in sequence:
    answer = max_el if (curr_el == max_el) else second
    print(answer)
