n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = list(a)
max_num = max(a)

for i in range(n):
    if a[i] == max_num and a.count(max_num) == 1:
        a.pop(i)
        print(max(a))
        a = list(b)
    else:
        print(max_num)