# -*- coding: utf-8 -*-
a = int(input())
c = [int(input()) for i in range(a)]

#最大値のindexを探し、最大値が複数あるか確認
all_max = max(c)
first_max_id = c.index(all_max)

c_dash = sorted(c,reversed=True)
second_max_value = c_dash[1]
for i,v in enumerate(c):
    if i != first_max_id:
        pr_val = all_max
    else:
        if all_max == second_max_value:
            pr_val = all_max
        else:
            pr_val = second_max_value
    print(pr_val)