N = int(input())
A = [int(input()) for _ in range(N)]
MAX = 0
SECOND = 0
MAX_COUNT = 0
for a in A:
    if a > MAX:
        MAX = a
        MAX_COUNT = 1
    elif a == MAX:
        MAX_COUNT += 1
    if a > SECOND and a != MAX:
        SECOND = a
for a in A:
    if a == MAX and MAX_COUNT == 1:
        print(SECOND)
    elif a == MAX and MAX_COUNT > 1:
        print(MAX)
    else:
        print(MAX)