import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = [int(input()) for _ in range(N)]

maxA = max(A)
lenA = len(A)

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print(max(A[1:]))
        elif i == lenA-1:
            print(max(A[:-1]))
        else:
            print(max(max(A[:i]), max(A[i+1:])))
    else:
        print(maxA)