n = int(input())
nums = [int(input()) for i in range(n)]
n_max = max(nums)
ex_nums = [i for i in nums].remove(n_max)
n_semi_max = max(ex_nums)
for i in nums:
    if i == n_max:
        print(n_semi_max)
    else:
        print(n_max)