import sys
n = int(input())
a = list(map(int, (input() for i in range(n))))

max = max(a)
tmp = sorted(set(a))
if len(tmp) > 1:
    max2 = tmp[-2]
else:
    max2 = max

for i in range(n):
    if a[i] == max:
        print(max2)
    else:
        print(max)

