def solve():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    num1=max(a)
    for i in range(n):
        if a[i]==num1:
            if i==0:
                print(max(a[1:]))
            elif i==n-1:
                print(max(a[:n-1]))
            else:
                print(max(max(a[:i]),max(a[i+1:])))
        else:
            print(num1)

solve()
