import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]
max_a = np.max(a)
for i in range(N):
    if a[i] != max_a:
        print(max_a)
    else:
#         print(i)
#         print(a[0:i]+a[i+1:])
        premax_a = np.max(a[0:i]+a[i+1:]) 
        print(premax_a)