n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
x = sorted(set(l))[-2]
ans = [m]*n
a = [index for index, value in enumerate(l) if value == m]
for i in a:
    ans[i] = x
[print(i) for i in ans]
