N = int(input())
A = []  # (index, Ai)
m = 2
m2 = 1
for i in range(N):
    a = int(input())
    A.append(a)
    if a > m:
        m2 = m
        m = a
    elif m >= a and a >= m2:
        m2 = a

for i in range(N):
    if A[i] == m:
        print(m2)
    else:
        print(m)
