N = int(input())
 
A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    if max1 < ai:
        max1 = ai
    elif max2 < ai:
        max2 = ai
 
    if max2 == 0:
        max2 = ai
 
    A.append((ai, max2, max1))

_, max2, max1 = A[N-1]
for i in range(N):
    ai, _, _ = A[i]


    if max1 == ai:
        print(max2)
    else:
        print(max1)