n = int(input())
a = list()
for i in range(n):
    x = input()
    a.append(int(x))
second = sorted(a)[-2]
m = max(a)
for i in range(n):
    if max(a) == a[i] and a.count(a[i]) == 1:
        print(second)
    else:
        print(m)