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

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

for row in range(N):
    row_value = values[row]
    if row_value != max_value:
        max_value = max(value_count_map.keys())
        print(max_value)
    elif value_count_map[row_value] != 1:
        max_value = max(value_count_map.keys())
        print(max_value)
    else:
        # if row value is a unique max value
        value_count = value_count_map.pop(row_value)
        max_value = max(value_count_map.keys())
        print(max_value)
        value_count_map[row_value] = value_count
