import copy
n = int(input())
a = [int(input()) for _ in range(n)]
b = copy.copy(a)
b.sort(reverse=True)
s = b[1]
m = max(a)

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