n = int(input())
a = [int(input()) for i in range(n)]

a_max = max(a)
max_idx = [i for i, x in enumerate(a) if x==a_max]

for i in range(n):
    if i in max_idx:
        copy = a[:]
        copy.pop(i)
        print(max(copy))
    else:
        print(a_max)