n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
first = max(a)
second_1 = sorted(a)
second = second_1[1]
for i in range(0, n):
    if a[i] == first:
        print(second)
    else:
        print(first)