# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
max = max(a)
for i in range(n):
    index = a.pop(i)
    if index == max:
        print(max(a))
    else:
        print(max)
    a.insert(i, index)
