n = int(input())
a = [int(input()) for i in range(n)]
b = [num for num in a]
x = max(a)
for i in range(n) :
    if a[i] != x :
        print(x)
    else :
        b.remove(a[i])
        print(max(b))
        b.append(a[i])