# -*- coding: utf-8 -*-

N = int(input())

values = [0]*N
max_value_count = 0
max_value = 0
next_max_value = max_value

for i in range(N):
    in_value = int(input())
    values[i] = in_value

    if in_value == max_value:
        max_value_count = max_value_count + 1
    elif in_value > max_value:
        next_max_value = max_value
        max_value = in_value
        max_value_count = 1
    elif in_value > next_max_value:
        next_max_value = in_value

max_value_count = value_count_map[max_value]

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)
